mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
We no longer allow extensions to provide generic parameters, and the
ability to parse the syntax
extension Array<String> { ... }
is causing confusion. Fixes rdar://problem/20873336.
Swift SVN r28468
73 lines
1.5 KiB
Swift
73 lines
1.5 KiB
Swift
// RUN: %target-parse-verify-swift
|
|
|
|
protocol P1 { typealias AssocType }
|
|
protocol P2 : P1 { }
|
|
protocol P3 { }
|
|
|
|
struct X<T : P1, U : P2, V> {
|
|
struct Inner<A, B : P3> { } // expected-error{{generic type 'Inner' nested in type}}
|
|
|
|
struct NonGenericInner { } // expected-error{{nested in generic type}}
|
|
}
|
|
|
|
struct Y {
|
|
struct Inner<A, B : P3> { } // expected-error{{generic type 'Inner' nested in type}}
|
|
|
|
struct NonGenericInner { }
|
|
}
|
|
|
|
struct Z<T : P1 where T.AssocType : P3> { }
|
|
|
|
extension X<T : P1, U : P2, V> { } // expected-error{{cannot extend a specialization of 'X'}}
|
|
extension Z<T : P1 where T.AssocType : P3> { } // expected-error{{cannot extend a specialization of 'Z'}}
|
|
extension X<Int> { } // expected-error{{cannot extend a specialization of 'X'}}
|
|
|
|
// Lvalue check when the archetypes are not the same.
|
|
struct LValueCheck<T> {
|
|
let x = 0
|
|
}
|
|
|
|
extension LValueCheck {
|
|
init(newY: Int) {
|
|
x = 42
|
|
}
|
|
}
|
|
|
|
// Member type references into another extension.
|
|
struct MemberTypeCheckA<T> { }
|
|
|
|
protocol MemberTypeProto {
|
|
typealias AssocType
|
|
|
|
func foo(a: AssocType)
|
|
init(_ assoc: MemberTypeCheckA<AssocType>)
|
|
}
|
|
|
|
struct MemberTypeCheckB<T> : MemberTypeProto {
|
|
func foo(a: T) {}
|
|
|
|
typealias Element = T
|
|
var t1: T
|
|
}
|
|
|
|
extension MemberTypeCheckB {
|
|
typealias Underlying = MemberTypeCheckA<T>
|
|
}
|
|
|
|
extension MemberTypeCheckB {
|
|
init(_ x: Underlying) { }
|
|
}
|
|
|
|
extension MemberTypeCheckB {
|
|
var t2: Element { return t1 }
|
|
}
|
|
|
|
// rdar://problem/19795284
|
|
extension Array {
|
|
var pairs: [(T,T)] {
|
|
get {
|
|
return []
|
|
}
|
|
}
|
|
}
|