Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Availability] Lazily expand type refinement contexts for extensions. #71365

Merged
merged 1 commit into from
Feb 5, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ class TypeRefinementContextBuilder : private ASTWalker {
return true;
}

if (isa<ExtensionDecl>(D)) {
return true;
}

return false;
}

Expand Down
10 changes: 10 additions & 0 deletions test/Macros/macro_expand_extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,13 @@ final class SendableClass {
@AddSendable
class InvalidSendableClass {
}

@AddSendable
struct HasNestedType {
struct Inner {}
}

// Make sure no circularity error is produced when resolving
// extensions of nested types when the outer type has an
// attached macro that can add other nested types.
extension HasNestedType.Inner {}
24 changes: 13 additions & 11 deletions test/Sema/availability_refinement_contexts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ protocol SomeProtocol {
var protoProperty: Int { get }
}

// CHECK-NEXT: {{^}} (decl versions=[10.51,+Inf) decl=extension.SomeClass
// CHECK-NEXT: {{^}} (decl versions=[10.52,+Inf) decl=someExtensionFunction()
// CHECK-NEXT: {{^}} (decl_implicit versions=[10.13,+Inf) decl=extension.SomeClass
// CHECK-NEXT: {{^}} (decl versions=[10.51,+Inf) decl=extension.SomeClass
// CHECK-NEXT: {{^}} (decl versions=[10.52,+Inf) decl=someExtensionFunction()
@available(OSX 10.51, *)
extension SomeClass {
@available(OSX 10.52, *)
Expand Down Expand Up @@ -207,15 +208,16 @@ func functionWithWhile() {
}
}

// CHECK-NEXT: {{^}} (decl versions=[10.51,+Inf) decl=extension.SomeClass
// CHECK-NEXT: {{^}} (decl_implicit versions=[10.51,+Inf) decl=someStaticPropertyWithClosureInit
// CHECK-NEXT: {{^}} (decl versions=[10.52,+Inf) decl=someStaticPropertyWithClosureInit
// CHECK-NEXT: {{^}} (condition_following_availability versions=[10.54,+Inf)
// CHECK-NEXT: {{^}} (if_then versions=[10.54,+Inf)
// CHECK-NEXT: {{^}} (decl_implicit versions=[10.51,+Inf) decl=someStaticPropertyWithClosureInitInferred
// CHECK-NEXT: {{^}} (decl versions=[10.52,+Inf) decl=someStaticPropertyWithClosureInitInferred
// CHECK-NEXT: {{^}} (condition_following_availability versions=[10.54,+Inf)
// CHECK-NEXT: {{^}} (if_then versions=[10.54,+Inf)
// CHECK-NEXT: {{^}} (decl_implicit versions=[10.13,+Inf) decl=extension.SomeClass
// CHECK-NEXT: {{^}} (decl versions=[10.51,+Inf) decl=extension.SomeClass
// CHECK-NEXT: {{^}} (decl_implicit versions=[10.51,+Inf) decl=someStaticPropertyWithClosureInit
// CHECK-NEXT: {{^}} (decl versions=[10.52,+Inf) decl=someStaticPropertyWithClosureInit
// CHECK-NEXT: {{^}} (condition_following_availability versions=[10.54,+Inf)
// CHECK-NEXT: {{^}} (if_then versions=[10.54,+Inf)
// CHECK-NEXT: {{^}} (decl_implicit versions=[10.51,+Inf) decl=someStaticPropertyWithClosureInitInferred
// CHECK-NEXT: {{^}} (decl versions=[10.52,+Inf) decl=someStaticPropertyWithClosureInitInferred
// CHECK-NEXT: {{^}} (condition_following_availability versions=[10.54,+Inf)
// CHECK-NEXT: {{^}} (if_then versions=[10.54,+Inf)
@available(OSX 10.51, *)
extension SomeClass {
@available(OSX 10.52, *)
Expand Down
6 changes: 6 additions & 0 deletions test/stdlib/Observation/Observable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ class GuardedAvailability {
}()
}

@Observable class Parent {
class Nested {}
}

extension Parent.Nested {}

struct CowContainer {
final class Contents { }

Expand Down