Skip to content

Commit 0063b8e

Browse files
committed
Add Regression Tests for Bogus Existential Checked Casts
Try to make sure we don't do the wrong thing here in the future. We've been accepting the optional code for a long long time. See rdar://57674858
1 parent 8261300 commit 0063b8e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/decl/protocol/protocols.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,17 @@ class C3 : P1 {} // expected-error{{type 'C3' does not conform to protocol 'P1'}
489489
func h<T : C3>(_ x : T) {
490490
_ = x as P1 // expected-error{{protocol 'P1' can only be used as a generic constraint because it has Self or associated type requirements}}
491491
}
492-
492+
func i<T : C3>(_ x : T?) -> Bool {
493+
return x is P1 // expected-error{{protocol 'P1' can only be used as a generic constraint because it has Self or associated type requirements}}
494+
// FIXME: Bogus diagnostic. See SR-11920.
495+
// expected-warning@-2 {{checking a value with optional type 'T?' against dynamic type 'P1' succeeds whenever the value is non-nil; did you mean to use '!= nil'?}}
496+
}
497+
func j(_ x : C1) -> Bool {
498+
return x is P1 // expected-error{{protocol 'P1' can only be used as a generic constraint because it has Self or associated type requirements}}
499+
}
500+
func k(_ x : C1?) -> Bool {
501+
return x is P1 // expected-error{{protocol 'P1' can only be used as a generic constraint because it has Self or associated type requirements}}
502+
}
493503

494504

495505
protocol P4 {

0 commit comments

Comments
 (0)