Files
swift-mirror/test/decl/protocol/recursive_requirement.swift
Doug Gregor 7677a454ea Move "non-self-conforming protocol type" check out of type validation.
Having semantic checking in type validation introduces the potential for more recursion, triggering crashes. By moving this semantic restriction out to a later stage, we make it more robust. Fixes 6 compiler crashers, although it regressed one compiler crasher that hits a different known issue (assertions in addGenericParameters when we have multiple parameters at the same depth).

Swift SVN r26226
2015-03-17 16:34:28 +00:00

88 lines
1.5 KiB
Swift

// RUN: %target-parse-verify-swift
// Basic test of requirements
protocol Foo {
typealias Bar : Foo
}
struct Oroborous : Foo {
typealias Bar = Oroborous
}
// More involved tests
protocol P {
typealias A : P
}
struct X<T: P> {
}
func f<T : P>(z: T) {
let x = X<T.A>()
}
protocol PP2 {
typealias A : P2 = Self
}
protocol P2 : PP2 {
typealias A = Self
}
struct X2<T: P2> {
}
struct Y2 : P2 {
typealias A = Y2
}
func f<T : P2>(z: T) {
let x = X2<T.A>()
}
protocol P3 {
typealias A: P4 = Self
}
protocol P4 : P3 {}
protocol DeclaredP : P3, P4 {}
struct Y3 : DeclaredP {
}
struct X3<T:P4> {}
func f2<T:P4>(a: T) {
let works = X3<T.A>()
}
f2(Y3())
protocol AsExistentialA {
var delegate : AsExistentialB? { get }
}
protocol AsExistentialB {
func aMethod(object : AsExistentialA)
}
protocol AsExistentialAssocTypeA {
var delegate : AsExistentialAssocTypeB? { get } // expected-error {{protocol 'AsExistentialAssocTypeB' can only be used as a generic constraint because it has Self or associated type requirements}}
}
protocol AsExistentialAssocTypeB {
func aMethod(object : AsExistentialAssocTypeA)
typealias Bar
}
protocol AsExistentialAssocTypeAgainA {
var delegate : AsExistentialAssocTypeAgainB? { get }
typealias Bar
}
protocol AsExistentialAssocTypeAgainB {
func aMethod(object : AsExistentialAssocTypeAgainA) // expected-error + {{protocol 'AsExistentialAssocTypeAgainA' can only be used as a generic constraint because it has Self or associated type requirements}}
}