Skip to content

Commit 1069225

Browse files
authored
Merge pull request #40074 from xedin/rdar-84879566
[ConstraintLocator] Allow simplification of constructor member with overloaded base
2 parents 0c70f56 + 6098417 commit 1069225

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4412,11 +4412,12 @@ void constraints::simplifyLocator(ASTNode &anchor,
44124412
}
44134413

44144414
case ConstraintLocator::ConstructorMember:
4415-
if (auto typeExpr = getAsExpr<TypeExpr>(anchor)) {
4416-
// This is really an implicit 'init' MemberRef, so point at the base,
4417-
// i.e. the TypeExpr.
4415+
// - This is really an implicit 'init' MemberRef, so point at the base,
4416+
// i.e. the TypeExpr.
4417+
// - For re-declarations we'd get an overloaded reference
4418+
// with multiple choices for the same type.
4419+
if (isExpr<TypeExpr>(anchor) || isExpr<OverloadedDeclRefExpr>(anchor)) {
44184420
range = SourceRange();
4419-
anchor = typeExpr;
44204421
path = path.slice(1);
44214422
continue;
44224423
}
@@ -5693,8 +5694,13 @@ SourceLoc constraints::getLoc(ASTNode anchor) {
56935694
return anchor.getStartLoc();
56945695
} else if (auto *S = anchor.dyn_cast<Stmt *>()) {
56955696
return S->getStartLoc();
5697+
} else if (auto *P = anchor.dyn_cast<Pattern *>()) {
5698+
return P->getLoc();
5699+
} else if (auto *C = anchor.dyn_cast<StmtCondition *>()) {
5700+
return C->front().getStartLoc();
56965701
} else {
5697-
return anchor.get<Pattern *>()->getLoc();
5702+
auto *I = anchor.get<CaseLabelItem *>();
5703+
return I->getStartLoc();
56985704
}
56995705
}
57005706

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)