mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #77333 from tshortli/defer-availability
Sema: TypeRefinementContextBuilder must not skip defer blocks
This commit is contained in:
@@ -550,10 +550,6 @@ private:
|
||||
}
|
||||
|
||||
bool shouldSkipDecl(Decl *D) const {
|
||||
// Implicit decls don't have source locations so they cannot have a TRC.
|
||||
if (D->isImplicit())
|
||||
return true;
|
||||
|
||||
// Only visit a node that has a corresponding concrete syntax node if we are
|
||||
// already walking that concrete syntax node.
|
||||
auto *concreteDecl = concreteSyntaxDeclForAvailableAttribute(D);
|
||||
@@ -568,6 +564,12 @@ private:
|
||||
PreWalkAction walkToDeclPre(Decl *D) override {
|
||||
PrettyStackTraceDecl trace(stackTraceAction(), D);
|
||||
|
||||
// Implicit decls don't have source locations so they cannot have a TRC.
|
||||
// However, some implicit nodes contain non-implicit nodes (e.g. defer
|
||||
// blocks) so continue rather than skipping the node entirely.
|
||||
if (D->isImplicit())
|
||||
return Action::Continue();
|
||||
|
||||
if (shouldSkipDecl(D))
|
||||
return Action::SkipNode();
|
||||
|
||||
|
||||
@@ -208,6 +208,16 @@ func functionWithWhile() {
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK-NEXT: {{^}} (decl version=51 decl=functionWithDefer()
|
||||
// CHECK-NEXT: {{^}} (condition_following_availability version=52
|
||||
// CHECK-NEXT: {{^}} (if_then version=52
|
||||
@available(OSX 51, *)
|
||||
func functionWithDefer() {
|
||||
defer {
|
||||
if #available(OSX 52, *) {}
|
||||
}
|
||||
}
|
||||
|
||||
// CHECK-NEXT: {{^}} (decl_implicit version=50 decl=extension.SomeClass
|
||||
// CHECK-NEXT: {{^}} (decl version=51 decl=extension.SomeClass
|
||||
// CHECK-NEXT: {{^}} (decl_implicit version=51 decl=someStaticPropertyWithClosureInit
|
||||
|
||||
@@ -28,7 +28,22 @@ let ignored3: Int = globalFuncAvailableOn52() // expected-error {{'globalFuncAva
|
||||
|
||||
// Functions without annotations should reflect the minimum deployment target.
|
||||
func functionWithoutAvailability() {
|
||||
// expected-note@-1 2{{add @available attribute to enclosing global function}}
|
||||
// expected-note@-1 5{{add @available attribute to enclosing global function}}
|
||||
|
||||
defer {
|
||||
let _: Int = globalFuncAvailableOn10_9()
|
||||
let _: Int = globalFuncAvailableOn51() // expected-error {{'globalFuncAvailableOn51()' is only available in macOS 51 or newer}}
|
||||
// expected-note@-1 {{add 'if #available' version check}}
|
||||
let _: Int = globalFuncAvailableOn52() // expected-error {{'globalFuncAvailableOn52()' is only available in macOS 52 or newer}}
|
||||
// expected-note@-1 {{add 'if #available' version check}}
|
||||
|
||||
if #available(OSX 51, *) {
|
||||
let _: Int = globalFuncAvailableOn10_9()
|
||||
let _: Int = globalFuncAvailableOn51()
|
||||
let _: Int = globalFuncAvailableOn52() // expected-error {{'globalFuncAvailableOn52()' is only available in macOS 52 or newer}}
|
||||
// expected-note@-1 {{add 'if #available' version check}}
|
||||
}
|
||||
}
|
||||
|
||||
let _: Int = globalFuncAvailableOn10_9()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user