Skip to content

Commit 6098417

Browse files
committed
[ConstraintLocator] Allow simplification of constructor member with overloaded base
`init` calls to redeclared types would end up diagnosed as ambiguity, so locator simplification needs to account for the fact that "base" of constructor might be overloaded type reference. Resolves: rdar://84879566
1 parent 4c415ab commit 6098417

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4410,11 +4410,12 @@ void constraints::simplifyLocator(ASTNode &anchor,
44104410
}
44114411

44124412
case ConstraintLocator::ConstructorMember:
4413-
if (auto typeExpr = getAsExpr<TypeExpr>(anchor)) {
4414-
// This is really an implicit 'init' MemberRef, so point at the base,
4415-
// i.e. the TypeExpr.
4413+
// - This is really an implicit 'init' MemberRef, so point at the base,
4414+
// i.e. the TypeExpr.
4415+
// - For re-declarations we'd get an overloaded reference
4416+
// with multiple choices for the same type.
4417+
if (isExpr<TypeExpr>(anchor) || isExpr<OverloadedDeclRefExpr>(anchor)) {
44164418
range = SourceRange();
4417-
anchor = typeExpr;
44184419
path = path.slice(1);
44194420
continue;
44204421
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct MyView: Tupled { // expected-note {{found this candidate}}
2+
var tuple: some Any {
3+
""
4+
}
5+
}
6+
7+
struct MyView: Tupled { // expected-note {{found this candidate}}
8+
var tuple: some Any {
9+
""
10+
}
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-frontend -typecheck -target x86_64-apple-macosx10.15 -swift-version 5 %S/Inputs/rdar84879566_invalid_decls.swift -primary-file %s -verify
2+
// REQUIRES: OS=macosx
3+
4+
protocol Tupled {
5+
associatedtype TupleType
6+
7+
@TupleBuilder var tuple: TupleType { get }
8+
}
9+
10+
@resultBuilder
11+
struct TupleBuilder {
12+
static func buildBlock() -> () {
13+
return ()
14+
}
15+
16+
static func buildBlock<T1>(_ t1: T1) -> (T1) {
17+
return (t1)
18+
}
19+
}
20+
21+
struct MyApp: Tupled {
22+
var tuple: some Any {
23+
MyView() // expected-error {{ambiguous use of 'init()'}}
24+
}
25+
}

0 commit comments

Comments
 (0)