Skip to content

GSB: Fix maybeResolveEquivalenceClass() with member type of superclass-constrained type [5.3] #31923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 103 additions & 137 deletions lib/AST/GenericSignatureBuilder.cpp

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions test/Constraints/same_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ func test6<T: Barrable>(_ t: T) -> (Y, X) where T.Bar == Y {
}

func test7<T: Barrable>(_ t: T) -> (Y, X) where T.Bar == Y, T.Bar.Foo == X {
// expected-warning@-1{{redundant same-type constraint 'T.Bar.Foo' == 'X'}}
// expected-note@-2{{same-type constraint 'T.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
// expected-warning@-1{{neither type in same-type constraint ('Y.Foo' (aka 'X') or 'X') refers to a generic parameter or associated type}}
return (t.bar, t.bar.foo)
}

func fail4<T: Barrable>(_ t: T) -> (Y, Z)
where
T.Bar == Y, // expected-note{{same-type constraint 'T.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
T.Bar.Foo == Z { // expected-error{{'T.Bar.Foo' cannot be equal to both 'Z' and 'Y.Foo' (aka 'X')}}
T.Bar == Y,
T.Bar.Foo == Z { // expected-error{{generic signature requires types 'Y.Foo' (aka 'X') and 'Z' to be the same}}
return (t.bar, t.bar.foo) // expected-error{{cannot convert return expression of type '(Y, X)' to return type '(Y, Z)'}}
}

Expand Down
3 changes: 3 additions & 0 deletions test/Generics/Inputs/sr8945-other.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public protocol P {
associatedtype T
}
17 changes: 17 additions & 0 deletions test/Generics/sr8945.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module %S/Inputs/sr8945-other.swift -emit-module-path %t/other.swiftmodule -module-name other
// RUN: %target-swift-frontend -emit-silgen %s -I%t

import other

public class C : P {
public typealias T = Int
}

public func takesInt(_: Int) {}

public func foo<T : C, S : Sequence>(_: T, _ xs: S) where S.Element == T.T {
for x in xs {
takesInt(x)
}
}
2 changes: 1 addition & 1 deletion test/IDE/print_ast_tc_decls_errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protocol AssociatedType1 {
// TYREPR: {{^}} associatedtype AssociatedTypeDecl4 : FooNonExistentProtocol, BarNonExistentProtocol{{$}}

associatedtype AssociatedTypeDecl5 : FooClass
// CHECK: {{^}} associatedtype AssociatedTypeDecl5 : FooClass{{$}}
// CHECK: {{^}} associatedtype AssociatedTypeDecl5{{$}}
}

//===---
Expand Down
2 changes: 1 addition & 1 deletion test/decl/protocol/req/recursion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct S<A: P> where A.T == S<A> { // expected-error {{circular reference
// expected-error@-2 {{generic struct 'S' references itself}}
func f(a: A.T) {
g(a: id(t: a))
// expected-error@-1 {{cannot convert value of type 'A.T' to expected argument type 'S<A>'}}
// expected-error@-1 {{type of expression is ambiguous without more context}}
_ = A.T.self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

protocol P {
associatedtype A : P where A.X == Self
// expected-error@-1{{'X' is not a member type of 'Self.A}}
associatedtype X : P where P.A == Self
// expected-error@-1{{associated type 'A' can only be used with a concrete type or generic parameter base}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ protocol P1 {
}
extension Foo: P1 where A : P1 {} // expected-error {{unsupported recursion for reference to associated type 'A' of type 'Foo<T>'}}
// expected-error@-1 {{type 'Foo<T>' does not conform to protocol 'P1'}}
// expected-error@-2 {{type 'Foo<T>' in conformance requirement does not refer to a generic parameter or associated type}}