Skip to content

Commit 32156b5

Browse files
committed
[RequirementMachine] Used loc in sig reqs.
`InferredGenericSignatureRequest` creates `StructuralRequirement`s for the requirements of the generic signature that is passed to it (if one is). Previously, it used invalid `SourceLoc`s for these requirements. The result was that when errors that were emitted as a result of those `StructuralRequirement`s (during concrete type contraction), they would also have invalid `SourceLoc`s. The effect was that those errors were ignored during `diagnoseRequirementErrors`. Here, use the available loc for those requirements. rdar://108963047
1 parent db823e4 commit 32156b5

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

lib/AST/RequirementMachine/RequirementMachineRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ InferredGenericSignatureRequest::evaluate(
770770
}();
771771

772772
for (const auto &req : parentSig.getRequirements())
773-
requirements.push_back({req, SourceLoc(), /*wasInferred=*/false});
773+
requirements.push_back({req, loc, /*wasInferred=*/false});
774774

775775
DeclContext *lookupDC = nullptr;
776776

test/Generics/rdar108963047.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol HasElt {
4+
associatedtype Element
5+
}
6+
struct IntElement : HasElt {
7+
typealias Element = Int
8+
}
9+
struct FloatElement : HasElt {
10+
typealias Element = Float
11+
}
12+
13+
struct G<T: HasElt> where T.Element == Float {
14+
func foo() where T == IntElement {} // expected-error {{generic signature requires types 'IntElement.Element' (aka 'Int') and 'Float' to be the same}}
15+
}

test/attr/attr_specialize.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extension Int: P {
1010

1111
public protocol ProtocolWithDep {
1212
associatedtype Element
13+
func getElement() -> Element
1314
}
1415

1516
public class C1 {
@@ -94,7 +95,7 @@ struct FloatElement : HasElt {
9495
typealias Element = Float
9596
}
9697
@_specialize(where T == FloatElement)
97-
@_specialize(where T == IntElement) // FIXME e/xpected-error{{'T.Element' cannot be equal to both 'IntElement.Element' (aka 'Int') and 'Float'}}
98+
@_specialize(where T == IntElement) // expected-error{{generic signature requires types 'IntElement.Element' (aka 'Int') and 'Float' to be the same}}
9899
func sameTypeRequirement<T : HasElt>(_ t: T) where T.Element == Float {}
99100

100101
@_specialize(where T == Sub)
@@ -333,3 +334,26 @@ public func testAvailability3<T>(_ t: T) {}
333334
// CHECK: public func testAvailability4<T>(_ t: T)
334335
@_specialize(exported: true, availability: SwiftStdlib 5.1, *; where T == Int)
335336
public func testAvailability4<T>(_ t: T) {}
337+
338+
public struct ExpectedElement {
339+
@inline(never)
340+
public func hello() {}
341+
}
342+
343+
public struct ConformerElement {}
344+
345+
public struct Conformer : ProtocolWithDep {
346+
public typealias Element = ConformerElement
347+
public func getElement() -> ConformerElement { return ConformerElement() }
348+
}
349+
350+
@inline(never)
351+
@_specialize(where T == Conformer) // expected-error{{generic signature requires types 'Conformer.Element' (aka 'ConformerElement') and 'ExpectedElement' to be the same}}
352+
public func foo<T : ProtocolWithDep>(_ t: T) where T.Element == ExpectedElement {
353+
t.getElement().hello()
354+
}
355+
356+
@_specialize(where T == Conformer) // expected-error{{generic signature requires types 'Conformer.Element' (aka 'ConformerElement') and 'ExpectedElement' to be the same}}
357+
public func bar<T : ProtocolWithDep>(_ t: T) where T.Element == ExpectedElement {
358+
foo(t)
359+
}

0 commit comments

Comments
 (0)