Skip to content

Commit 5be6b9f

Browse files
committed
Use Location of Inference Sources as a Fallback
It's possible for the requirement machine to fail to pick up a source location for its computed errors to attach to when 1) The declaration has no where clause 2) Nor does it have a generic parameter list This is possible because of the magic of desugaring opaque types in input position to generic parameters a la func foo(_ : some P<T, U>) Try to use the first valid user-written inference source to derive a location. rdar://92105516
1 parent 5aa05b2 commit 5be6b9f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,11 @@ InferredGenericSignatureRequestRQM::evaluate(
787787
// types and such.
788788
for (auto sourcePair : inferenceSources) {
789789
auto *typeRepr = sourcePair.getTypeRepr();
790-
auto loc = typeRepr ? typeRepr->getStartLoc() : SourceLoc();
790+
auto typeLoc = typeRepr ? typeRepr->getStartLoc() : SourceLoc();
791+
if (loc.isInvalid())
792+
loc = typeLoc;
791793

792-
inferRequirements(sourcePair.getType(), loc, moduleForInference,
794+
inferRequirements(sourcePair.getType(), typeLoc, moduleForInference,
793795
requirements);
794796
}
795797

test/type/parameterized_existential.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ func saturation(_ dry: any Sponge, _ wet: any Sponge<Int, Int>) {
6262
_ = wet as any Sponge<String, String> // expected-error {{'any Sponge<Int, Int>' is not convertible to 'any Sponge<String, String>'}}
6363
// expected-note@-1 {{did you mean to use 'as!' to force downcast?}}
6464
}
65+
66+
protocol Pair<X, Y> where Self.X == Self.Y {
67+
associatedtype X
68+
associatedtype Y
69+
}
70+
71+
func splay(_ x: some Pair<Int, String>) -> (Int, String) { fatalError() }
72+
// expected-error@-1 {{no type for 'some Pair<Int, String>.X' can satisfy both 'some Pair<Int, String>.X == String' and 'some Pair<Int, String>.X == Int'}}

0 commit comments

Comments
 (0)