Files
swift-mirror/validation-test/compiler_crashers_2_fixed/sr12327.swift
Slava Pestov 6d84c18ba4 Sema: Check 'where' clause requirements on type witnesses
In the included test case, conformance checking of Wrapper : B would
pick up typealias Foo as a witness for the associated type B.Foo.

However, this typealias Foo is defined in a constrained extension where
T : A, and the underlying type references the associated type A.Foo
on T.

The resulting substitution is invalid when the conformance Wrapper : B
is used in a context where T does not conform to A.

Instead, we should ignore this typealias entirely, since it appears
in an unusable constrained extension.

Fixes <rdar://problem/60219705>, <https://bugs.swift.org/browse/SR-12327>,
<https://bugs.swift.org/browse/SR-12663>.
2020-08-15 01:43:13 -04:00

43 lines
886 B
Swift

// RUN: %target-swift-frontend -emit-ir -O %s
protocol A {
associatedtype Foo // Does not crash if renamed
}
protocol B {
associatedtype Foo // Does not crash if renamed
var aFoo: Foo { get }
}
public struct Wrapper<T> {
let wrapped: T
}
// Removing this extension or combining it with the next one prevents the crash
extension Wrapper: A where T: A {
typealias Foo = Wrapper<T.Foo>
}
extension Wrapper: B where T: B {
var aFoo: Wrapper<T.Foo> {
return .init(wrapped: wrapped.aFoo)
}
}
public struct Model: B {
public struct Foo {}
public var aFoo: Foo {
return Foo()
}
}
// Attempting to specialize this method for Wrapper<Model> crashes the compiler
func fooString<Body: B>(body: Body) -> String {
return "\(body.aFoo)"
}
public func foo(_ command: Wrapper<Model>) -> String {
return fooString(body: command)
}