swift
4c2b5646 - Report unnecessary availability warnings independently from the deployment target (#37394)

Commit
4 years ago
Report unnecessary availability warnings independently from the deployment target (#37394) This change separates emission of the diagnostics like: ``` unnecessary check for 'Platform'; enclosing scope ensures guard will always be true ``` from the deployment target of the current compilation. Instead, these diagnostics will only be emitted if the enclosing scope guard is explicitly specified by the user with an `#availability` attribute. This fixes cases like the following: ``` @available(macOS 11.0, *) class Foo { func foo() { if #available(macOS 11.1, *) {} } } ``` Compiling this with `-target x86_64-apple-macos11.2` results in: ``` warning: unnecessary check for 'macOS'; enclosing scope ensures guard will always be true if #available(macOS 11.1, *) {} .../test.swift:2:7: note: enclosing scope here class Foo { ``` Even though in source-code the enclosing scope (`Foo`) of this guard does not ensure it will always be true. This happens because availability range is propagated by intersecting ranges top-down from the root `TypeRefinementContext`, which is defined by the deployment target, causing the availability range on class `Foo` to become `11.2`. Users may be sharing the same piece of source-code across different projects with their own respective deployment targets which makes such target-dependent warnings confusing at some times, and not-useful at others. We should rather have the warning simply reflect what is in the source. Resolves rdar://77607488
Author
Parents
Loading