mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
We noticed that a project failed to build with prepared overloads enabled, but built successfully with prepared overloads disabled. It turns out that the code clearly should never have been accepted in the first place, because the type checker was making an arbitrary choice between two nominal type declarations with the same name. Further inspection revealed this was because of a FIXME added in 2013 which was far too broad. Tighten up the logic here to only disambiguate if at least one of the two declarations is a type alias, and it has the same underlying type as the other one. A choice between unrelated nominal type declarations should always be ambiguous. This still isn't perfect, because we might have two generic type aliases that are referenced in both solutions with different substitution maps, in which case we will still erroneously pick the first one. But this is better than the old logic, at least. Fixes rdar://165863775.
28 lines
821 B
Swift
28 lines
821 B
Swift
// RUN: %target-typecheck-verify-swift -swift-version 6
|
|
// Checks that the compiler correctly diagnoses ambiguous initializers using
|
|
// trailing closures, rather than crashing.
|
|
//
|
|
// Fixes #85364
|
|
|
|
struct S1 { // expected-note {{found this candidate}} \
|
|
// expected-note {{'S1' previously declared here}}
|
|
var c: () -> Void
|
|
}
|
|
|
|
S1 {} // expected-error {{ambiguous use of 'S1'}}
|
|
|
|
struct S1 { // expected-note {{found this candidate}} \
|
|
// expected-error {{invalid redeclaration of 'S1'}}
|
|
func callAsFunction(_: () -> Void) {}
|
|
}
|
|
|
|
struct S2 {
|
|
init() {} // expected-note {{found this candidate}}
|
|
|
|
init(_ block: () -> Void) { block() } // expected-note {{found this candidate}}
|
|
|
|
func callAsFunction(_ block: () -> Void) { block() }
|
|
}
|
|
|
|
S2 {} // expected-error {{ambiguous use of 'init'}}
|