Sema: Diagnose opaque types that depend on availability of a custom domain.

Serialization and IRGen don't yet support opaque return types that would depend
on querying availability of a custom domain so we need to reject this code to
avoid mis-compiling it.
This commit is contained in:
Allan Shortlidge
2025-06-25 15:22:54 -07:00
parent 4a76c04cf5
commit 59d74fa1c7
3 changed files with 45 additions and 1 deletions

View File

@@ -193,3 +193,19 @@ struct EnabledDomainAvailable {
unavailableInDisabledDomain() // expected-error {{'unavailableInDisabledDomain()' is unavailable}}
}
}
protocol P { }
@available(EnabledDomain)
struct AvailableInEnabledDomain: P { }
@available(EnabledDomain, unavailable)
struct UnavailableInEnabledDomain: P { }
func testOpaqueReturnType() -> some P {
if #available(EnabledDomain) { // expected-error {{opaque return type cannot depend on EnabledDomain availability}}
return AvailableInEnabledDomain()
} else {
return UnavailableInEnabledDomain()
}
}