Skip to content

Commit c2e5d04

Browse files
committed
Test: Find better locations for some updated tests
1 parent 396087d commit c2e5d04

File tree

7 files changed

+71
-117
lines changed

7 files changed

+71
-117
lines changed

test/Generics/function_defs.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ func otherExistential<T : EqualComparable>(_ t1: T) {
5656
_ = t1 as EqualComparable & OtherEqualComparable // expected-error{{value of type 'T' does not conform to 'EqualComparable & OtherEqualComparable' in coercion}}
5757
}
5858

59-
protocol Runcible {
60-
func runce<A>(_ x: A)
61-
func spoon(_ x: Self)
62-
}
63-
64-
func testRuncible(_ x: Runcible) { // Ok
65-
x.runce(5)
66-
}
67-
6859
//===----------------------------------------------------------------------===//
6960
// Overloading
7061
//===----------------------------------------------------------------------===//

test/Sema/existential_nested_type.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/decl/nested/type_in_function.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,6 @@ func genericFunction<T>(t: T) {
135135
// expected-error@-2 {{'Second' inherits from itself}}
136136
}
137137

138-
// Spurious "Self or associated type requirements" diagnostic.
139-
protocol ProtoWithAssocType {
140-
associatedtype T = Int
141-
}
142-
143-
func freeFunction() {
144-
struct ConformingType : ProtoWithAssocType {
145-
typealias T = Int
146-
147-
func method() -> ProtoWithAssocType {} // Ok
148-
}
149-
}
150-
151138
// Superclass lookup archetype vs interface type mixup
152139
class Generic<T> {
153140
struct Nested {}

test/decl/protocol/protocols.swift

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -263,55 +263,6 @@ struct WrongIsEqual : IsEqualComparable { // expected-error{{type 'WrongIsEqual'
263263
func isEqual(other: Int) -> Bool {} // expected-note{{candidate has non-matching type '(Int) -> Bool'}}
264264
}
265265

266-
//===----------------------------------------------------------------------===//
267-
// Using values of existential type.
268-
//===----------------------------------------------------------------------===//
269-
270-
func existentialSequence(_ e: Sequence) {
271-
var x = e.makeIterator() // expected-error{{member 'makeIterator' cannot be used on value of protocol type 'Sequence'; use a generic constraint instead}}
272-
x.next()
273-
x.nonexistent()
274-
}
275-
276-
protocol HasSequenceAndStream {
277-
associatedtype R : IteratorProtocol, Sequence
278-
func getR() -> R
279-
}
280-
281-
func existentialSequenceAndStreamType(_ h: HasSequenceAndStream) {
282-
// FIXME: Crummy diagnostics.
283-
var x = h.getR() // expected-error{{member 'getR' cannot be used on value of protocol type 'HasSequenceAndStream'; use a generic constraint instead}}
284-
x.makeIterator()
285-
x.next()
286-
287-
x.nonexistent()
288-
}
289-
290-
//===----------------------------------------------------------------------===//
291-
// Subscripting
292-
//===----------------------------------------------------------------------===//
293-
protocol IntIntSubscriptable {
294-
subscript (i: Int) -> Int { get }
295-
}
296-
297-
protocol IntSubscriptable {
298-
associatedtype Element
299-
subscript (i: Int) -> Element { get }
300-
}
301-
302-
struct DictionaryIntInt {
303-
subscript (i: Int) -> Int {
304-
get {
305-
return i
306-
}
307-
}
308-
}
309-
310-
func testSubscripting(_ iis: IntIntSubscriptable, i_s: IntSubscriptable) { // Ok
311-
var i: Int = iis[17]
312-
var i2 = i_s[17] // expected-error{{member 'subscript' cannot be used on value of protocol type 'IntSubscriptable'; use a generic constraint instead}}
313-
}
314-
315266
//===----------------------------------------------------------------------===//
316267
// Static methods
317268
//===----------------------------------------------------------------------===//

test/decl/protocol/protocols_with_self_or_assoc_reqs.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,51 @@ do {
470470
instance[static_invariantSelfSubscript: ()] // expected-error {{member 'subscript' cannot be used on value of protocol type 'P1_TypeMemberOnInstanceAndViceVersa'; use a generic constraint instead}}
471471
}
472472
}
473+
474+
// Settable storage members with a 'Self' result type may not be used with an
475+
// existential base.
476+
protocol P2 {
477+
subscript() -> Self { get set }
478+
479+
var prop: Self { get set }
480+
}
481+
func takesP2(p2: P2) {
482+
_ = p2[]
483+
// expected-error@-1{{member 'subscript' cannot be used on value of protocol type 'P2'; use a generic constraint instead}}
484+
_ = p2.prop
485+
// expected-error@-1{{member 'prop' cannot be used on value of protocol type 'P2'; use a generic constraint instead}}
486+
}
487+
488+
protocol MiscTestsProto {
489+
associatedtype Assoc
490+
func runce<A>(_: A)
491+
func spoon(_: Self)
492+
493+
associatedtype R : IteratorProtocol, Sequence
494+
func getR() -> R
495+
496+
subscript(intToAssoc _: Int) -> Assoc { get }
497+
subscript(intToInt _: Int) -> Int { get }
498+
}
499+
do {
500+
func miscTests(_ arg: MiscTestsProto) { // ok
501+
arg.runce(5)
502+
503+
do {
504+
// FIXME: Crummy diagnostics.
505+
var x = arg.getR() // expected-error{{member 'getR' cannot be used on value of protocol type 'MiscTestsProto'; use a generic constraint instead}}
506+
x.makeIterator()
507+
x.next()
508+
x.nonexistent()
509+
}
510+
511+
var _: Int = arg[intToInt: 17]
512+
_ = arg[intToAssoc: 17] // expected-error{{member 'subscript' cannot be used on value of protocol type 'MiscTestsProto'; use a generic constraint instead}}
513+
}
514+
515+
func existentialSequence(_ e: Sequence) {
516+
var x = e.makeIterator() // expected-error{{member 'makeIterator' cannot be used on value of protocol type 'Sequence'; use a generic constraint instead}}
517+
x.next()
518+
x.nonexistent()
519+
}
520+
}

test/decl/protocol/req/dynamic_self.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,3 @@ enum EError : P { // expected-error{{type 'EError' does not conform to protocol
8686
subscript() -> Int { 0 } // expected-note{{candidate has non-matching type '() -> Int'}}
8787
func f() -> Int { 0 } // expected-note{{candidate has non-matching type '() -> Int'}}
8888
}
89-
90-
// Settable storage members with a 'Self' result type may not be used with an
91-
// existential base.
92-
protocol P5 {
93-
}
94-
extension P5 {
95-
var prop: Self {
96-
get { self }
97-
set { }
98-
}
99-
100-
subscript() -> Self {
101-
get { self }
102-
set { }
103-
}
104-
}
105-
func takesP5(p5: P5) {
106-
_ = p5[]
107-
// expected-error@-1{{member 'subscript' cannot be used on value of protocol type 'P5'; use a generic constraint instead}}
108-
_ = p5.prop
109-
// expected-error@-1{{member 'prop' cannot be used on value of protocol type 'P5'; use a generic constraint instead}}
110-
}

test/type/protocol_types.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,33 @@ protocol HasAssoc {
6767
func foo()
6868
}
6969

70+
do {
71+
enum MyError : Error {
72+
case bad(Any)
73+
}
74+
75+
func checkIt(_ js: Any) throws {
76+
switch js {
77+
case let dbl as HasAssoc:
78+
throw MyError.bad(dbl)
79+
80+
default:
81+
fatalError("wrong")
82+
}
83+
}
84+
}
85+
7086
func testHasAssoc(_ x: Any, _: HasAssoc) {
7187
if let p = x as? HasAssoc {
7288
p.foo() // don't crash here.
7389
}
90+
91+
struct ConformingType : HasAssoc {
92+
typealias Assoc = Int
93+
func foo() {}
94+
95+
func method() -> HasAssoc {}
96+
}
7497
}
7598

7699
// SR-38

0 commit comments

Comments
 (0)