-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[TypeChecker] Produce a tailored diagnostic for for-in
sequence fai…
#27834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ struct BadContainer1 { | |
} | ||
|
||
func bad_containers_1(bc: BadContainer1) { | ||
for e in bc { } // expected-error{{type 'BadContainer1' does not conform to protocol 'Sequence'}} | ||
for e in bc { } // expected-error{{for-in loop requires 'BadContainer1' to conform to 'Sequence'}} | ||
// expected-error@-1{{variable 'e' is not bound by any pattern}} | ||
} | ||
|
||
|
@@ -15,7 +15,7 @@ struct BadContainer2 : Sequence { // expected-error{{type 'BadContainer2' does n | |
|
||
func bad_containers_2(bc: BadContainer2) { | ||
for e in bc { } | ||
// expected-error@-1{{variable 'e' is not bound by any pattern}} | ||
// expected-warning@-1 {{immutable value 'e' was never used; consider replacing with '_' or removing it}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this and a few others below suddenly become valid? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everywhere |
||
} | ||
|
||
struct BadContainer3 : Sequence { // expected-error{{type 'BadContainer3' does not conform to protocol 'Sequence'}} | ||
|
@@ -24,7 +24,7 @@ struct BadContainer3 : Sequence { // expected-error{{type 'BadContainer3' does n | |
|
||
func bad_containers_3(bc: BadContainer3) { | ||
for e in bc { } | ||
// expected-error@-1{{variable 'e' is not bound by any pattern}} | ||
// expected-warning@-1 {{immutable value 'e' was never used; consider replacing with '_' or removing it}} | ||
} | ||
|
||
struct BadIterator1 {} | ||
|
@@ -36,7 +36,7 @@ struct BadContainer4 : Sequence { // expected-error{{type 'BadContainer4' does n | |
|
||
func bad_containers_4(bc: BadContainer4) { | ||
for e in bc { } | ||
// expected-error@-1{{variable 'e' is not bound by any pattern}} | ||
// expected-warning@-1 {{immutable value 'e' was never used; consider replacing with '_' or removing it}} | ||
} | ||
|
||
// Pattern type-checking | ||
|
@@ -176,10 +176,8 @@ func testMatchingPatterns() { | |
// <rdar://problem/21662365> QoI: diagnostic for for-each over an optional sequence isn't great | ||
func testOptionalSequence() { | ||
let array : [Int]? | ||
for x in array { // expected-error {{value of optional type '[Int]?' must be unwrapped}} | ||
// expected-note@-1{{coalesce}} | ||
// expected-note@-2{{force-unwrap}} | ||
// expected-error@-3{{variable 'x' is not bound by any pattern}} | ||
for x in array { // expected-error {{for-in loop requires '[Int]?' to conform to 'Sequence'; did you mean to unwrap optional?}} | ||
// expected-error@-1{{variable 'x' is not bound by any pattern}} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically not accurate, the requirement is not coming from the Sequence protocol itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diagnostics here aren't great because we still don't have a full coverage, but that's something on my radar.