Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,6 @@ class TypeRefinementContextBuilder : private ASTWalker {
}

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);
Expand All @@ -568,6 +564,12 @@ class TypeRefinementContextBuilder : private ASTWalker {
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();

Expand Down
10 changes: 10 additions & 0 deletions test/Sema/availability_refinement_contexts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion test/Sema/availability_versions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down