Skip to content

Commit 52c732f

Browse files
authored
Merge pull request #68169 from xedin/rdar-67799
[ConstraintSystem] Look through specialization while simplifying cons…
2 parents 9dbb9e4 + e00034e commit 52c732f

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

lib/Sema/ConstraintSystem.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -5724,6 +5724,13 @@ void constraints::simplifyLocator(ASTNode &anchor,
57245724
}
57255725

57265726
case ConstraintLocator::ConstructorMember:
5727+
// Look through specialization first, because it doesn't play a
5728+
// functional role here.
5729+
if (auto *USE = getAsExpr<UnresolvedSpecializeExpr>(anchor)) {
5730+
anchor = USE->getSubExpr();
5731+
range = anchor.getSourceRange();
5732+
}
5733+
57275734
// - This is really an implicit 'init' MemberRef, so point at the base,
57285735
// i.e. the TypeExpr.
57295736
// - For re-declarations we'd get an overloaded reference
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %empty-directory(%t/src)
2+
// RUN: %empty-directory(%t/sdk)
3+
// RUN: split-file %s %t/src
4+
5+
// RUN: %target-swift-frontend -emit-module %t/src/A.swift \
6+
// RUN: -module-name A -swift-version 5 -enable-library-evolution \
7+
// RUN: -emit-module-path %t/A.swiftmodule
8+
9+
// RUN: %target-swift-frontend -emit-module %t/src/B.swift \
10+
// RUN: -I %t -module-name B -swift-version 5 -enable-library-evolution \
11+
// RUN: -emit-module-path %t/B.swiftmodule
12+
13+
// RUN: %target-swift-frontend -typecheck %t/src/main.swift \
14+
// RUN: -module-name main -I %t -verify
15+
16+
// https://github.com/apple/swift/issues/67799
17+
18+
//--- A.swift
19+
public final class S<T> {
20+
public init(t: T) {
21+
}
22+
23+
public func test() {}
24+
public static func staticFn() {}
25+
}
26+
27+
//--- B.swift
28+
public final class S<T> {
29+
public init(t: T) {
30+
}
31+
32+
public func test() {}
33+
public static func staticFn() {}
34+
}
35+
36+
//--- main.swift
37+
import A
38+
import B
39+
40+
func test() {
41+
_ = S<Int>(t: 42) // expected-error {{ambiguous use of 'init(t:)'}}
42+
43+
S<Int>(t: 42).test() // expected-error {{ambiguous use of 'init(t:)'}}
44+
45+
// FIXME(diagnostics): This should produce ambiguity diagnostic too
46+
S<Int>.staticFn()
47+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
48+
}

0 commit comments

Comments
 (0)