Skip to content

Commit eb1bdee

Browse files
authored
Merge pull request #71539 from slavapestov/assoc-type-regression-fixes-2
Three more associated type inference fixes
2 parents e0fda80 + 23ef893 commit eb1bdee

9 files changed

+401
-205
lines changed

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 204 additions & 85 deletions
Large diffs are not rendered by default.

test/Distributed/actor_protocols.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ actor A2: DistributedActor {
6767
final class DA2: DistributedActor {
6868
// expected-error@-1{{non-actor type 'DA2' cannot conform to the 'AnyActor' protocol}}
6969
// expected-error@-2{{non-distributed actor type 'DA2' cannot conform to the 'DistributedActor' protocol}}
70-
// expected-error@-3{{'DistributedActor' requires the types 'ObjectIdentifier' and 'FakeActorSystem.ActorID' (aka 'ActorAddress') be equivalent}}
71-
// expected-note@-4{{requirement specified as 'Self.ID' == 'Self.ActorSystem.ActorID' [with Self = DA2]}}
7270
nonisolated var id: ID {
7371
fatalError()
7472
}

test/decl/protocol/req/associated_type_inference_fixed_type_experimental_inference.swift

Lines changed: 89 additions & 118 deletions
Large diffs are not rendered by default.

test/decl/protocol/req/associated_type_inference_tautology_2.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ struct S: P {
1818
func f(_: Float) {}
1919
func f(_: String) {}
2020
}
21+
22+
let x: String.Type = S.A.self
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-associated-type-inference
2+
// RUN: %target-typecheck-verify-swift -disable-experimental-associated-type-inference
3+
4+
public protocol LazySequenceProtocol: Sequence {
5+
associatedtype Elements: Sequence = Self where Elements.Element == Element
6+
}
7+
8+
public struct S<Base: Sequence>: LazySequenceProtocol {
9+
public struct Iterator: IteratorProtocol {
10+
public mutating func next() -> Base.Element? {
11+
fatalError()
12+
}
13+
}
14+
15+
public func makeIterator() -> Iterator {
16+
fatalError()
17+
}
18+
}
19+
20+
let x: Int.Type = S<Array<Int>>.Element.self
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-associated-type-inference
2+
// RUN: %target-typecheck-verify-swift -disable-experimental-associated-type-inference
3+
4+
public struct DefaultA {}
5+
6+
public protocol P {
7+
associatedtype A = DefaultA
8+
associatedtype B
9+
10+
static func foo(_: A, _: B)
11+
static func bar(_: B)
12+
}
13+
14+
extension P {
15+
public static func foo(_: A, _: B) where B == Void {}
16+
}
17+
18+
// The only way C can conform to P is with 'A := DefaultA' and 'B := String'.
19+
// We skip C.foo() because it contains 'A', so we must not infer 'B := Void'
20+
// from P.foo() above.
21+
class C: P {
22+
public static func foo(_: A, _: String) {}
23+
public static func bar(_: String) {}
24+
}
25+
26+
let x: DefaultA.Type = C.A.self
27+
let y: String.Type = C.B.self

test/decl/protocol/req/rdar122586685.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ extension P {
1212
public subscript(index: Int) -> String { fatalError() }
1313
public func makeIterator() -> AnyIterator<String> { fatalError() }
1414
}
15+
16+
let x: AnyIterator<String>.Type = S.Iterator.self
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-associated-type-inference
2+
// RUN: %target-typecheck-verify-swift -disable-experimental-associated-type-inference
3+
4+
public protocol P1 {
5+
associatedtype A
6+
func f() -> A
7+
}
8+
9+
public struct S1 {}
10+
11+
extension Int: P1 {
12+
public func f() -> S1 { fatalError() }
13+
}
14+
15+
public protocol P2: RawRepresentable, P1 {}
16+
17+
public struct S2 {}
18+
19+
extension P2 where RawValue == S2, A == S2 {
20+
// This is not a candidate witness, because we require A == S1.
21+
public func f() -> A { fatalError() }
22+
}
23+
24+
extension P2 where RawValue: P1, RawValue.A == A {
25+
// This is a candidate witness.
26+
public func f() -> A { fatalError() }
27+
}
28+
29+
public protocol P3: P2 where A == S1, RawValue == Int {}
30+
31+
// When checking [S3: P1], the fact that P3 has [A == S1] should completely
32+
// solve everything.
33+
public struct S3: P3 {
34+
public init(rawValue: Int) { fatalError() }
35+
public var rawValue: Int { fatalError() }
36+
}
37+
38+
let x: S1.Type = S3.A.self
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-associated-type-inference
2+
// RUN: %target-typecheck-verify-swift -disable-experimental-associated-type-inference
3+
4+
struct G<T> {
5+
class Nested {}
6+
}
7+
8+
extension G.Nested: Sequence {
9+
func makeIterator() -> AnyIterator<String> { fatalError() }
10+
}
11+
12+
extension G: LazySequenceProtocol, IteratorProtocol {
13+
mutating func next() -> Int? { fatalError() }
14+
}
15+
16+
let c: G<Float>.Type = G<Float>.Iterator.self
17+
let n: Int.Type = G<Float>.Element.self
18+
let d: AnyIterator<String>.Type = G<Float>.Nested.Iterator.self
19+
let s: String.Type = G<Float>.Nested.Element.self

0 commit comments

Comments
 (0)