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.
48 lines
1.1 KiB
Swift
48 lines
1.1 KiB
Swift
// RUN: %empty-directory(%t/src)
|
|
// RUN: %empty-directory(%t/sdk)
|
|
// RUN: split-file %s %t/src
|
|
|
|
// RUN: %target-swift-frontend -emit-module %t/src/A.swift \
|
|
// RUN: -module-name A -swift-version 5 -enable-library-evolution \
|
|
// RUN: -emit-module-path %t/A.swiftmodule
|
|
|
|
// RUN: %target-swift-frontend -emit-module %t/src/B.swift \
|
|
// RUN: -I %t -module-name B -swift-version 5 -enable-library-evolution \
|
|
// RUN: -emit-module-path %t/B.swiftmodule
|
|
|
|
// RUN: %target-swift-frontend -typecheck %t/src/main.swift \
|
|
// RUN: -module-name main -I %t -verify -verify-ignore-unrelated
|
|
|
|
// https://github.com/apple/swift/issues/67799
|
|
|
|
//--- A.swift
|
|
public final class S<T> {
|
|
public init(t: T) {
|
|
}
|
|
|
|
public func test() {}
|
|
public static func staticFn() {}
|
|
}
|
|
|
|
//--- B.swift
|
|
public final class S<T> {
|
|
public init(t: T) {
|
|
}
|
|
|
|
public func test() {}
|
|
public static func staticFn() {}
|
|
}
|
|
|
|
//--- main.swift
|
|
import A
|
|
import B
|
|
|
|
func test() {
|
|
_ = S<Int>(t: 42) // expected-error {{ambiguous use of 'S'}}
|
|
|
|
S<Int>(t: 42).test() // expected-error {{ambiguous use of 'S'}}
|
|
|
|
S<Int>.staticFn()
|
|
// expected-error@-1 {{ambiguous use of 'S'}}
|
|
}
|