Skip to content

Commit f52593b

Browse files
committed
[RequirementMachine] Record the sugared 'Self' type parameter when
initializing a RequirementMachine for a written protocol signature. These generic parameters are used for re-sugaring when computing a type from a term, so if the recorded 'Self' parameter is canonicalized, it shows up in diagnostics as 'tau_0_0'.
1 parent a4230a6 commit f52593b

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ RequirementMachine::initWithProtocolWrittenRequirements(
366366

367367
// For RequirementMachine::verify() when called by generic signature queries;
368368
// We have a single valid generic parameter at depth 0, index 0.
369-
Params.push_back(component[0]->getSelfInterfaceType()->getCanonicalType());
369+
Params.push_back(component[0]->getSelfInterfaceType());
370370

371371
if (Dump) {
372372
llvm::dbgs() << "Adding protocols";

test/Generics/concrete_conflict.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
2-
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -typecheck -verify %s -debug-generic-signatures -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
32

43
protocol P1 {
54
associatedtype T where T == Int
@@ -25,11 +24,11 @@ protocol P3 {
2524
// CHECK-LABEL: .P4@
2625
// CHECK-LABEL: Requirement signature: <Self where Self.[P4]T : P1, Self.[P4]T : P2, Self.[P4]T : P3>
2726

27+
// expected-error@+3{{no type for 'Self.T.T' can satisfy both 'Self.T.T == Int' and 'Self.T.T == String'}}
28+
// expected-error@+2{{no type for 'Self.T.T' can satisfy both 'Self.T.T == Int' and 'Self.T.T == Float'}}
29+
// expected-error@+1{{no type for 'Self.T.T' can satisfy both 'Self.T.T == String' and 'Self.T.T == Float'}}
2830
protocol P4 {
2931
associatedtype T : P1 & P2 & P3
30-
// expected-note@-1 2{{same-type constraint 'Self.T.T' == 'Int' implied here}}
31-
// expected-error@-2 {{'Self.T.T' cannot be equal to both 'String' and 'Int'}}
32-
// expected-error@-3 {{'Self.T.T' cannot be equal to both 'Float' and 'Int'}}
3332
}
3433

3534
class Class<T> {}
@@ -38,5 +37,5 @@ extension Class where T == Bool {
3837
// CHECK-LABEL: .badRequirement()@
3938
// CHECK-NEXT: <T>
4039
func badRequirement() where T == Int { }
41-
// expected-error@-1 {{generic parameter 'T' cannot be equal to both 'Int' and 'Bool'}}
42-
}
40+
// expected-error@-1 {{no type for 'T' can satisfy both 'T == Bool' and 'T == Int'}}
41+
}

test/Generics/protocol_self_concrete_error.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77

88
struct S {}
99

10+
// expected-error@+1 {{no type for 'Self' can satisfy both 'Self : P' and 'Self == S'}}
1011
protocol P where Self == S {}

0 commit comments

Comments
 (0)