-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] if let value on async value should be banned (not crash) #74475
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
test/Concurrency/effectful_properties_async_if_optional_unwrap.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// RUN: %target-swift-frontend -parse-as-library -emit-sil -verify %s | ||
|
||
// REQUIRES: concurrency | ||
|
||
@available(SwiftStdlib 5.1, *) | ||
struct Kappa { | ||
var maybeData: Int? { | ||
get async { 12 } | ||
} | ||
|
||
func take() -> Int? { // expected-note 3{{add 'async' to function 'take()' to make it asynchronous}} | ||
|
||
if let data = maybeData { // expected-error{{'async' property access in a function that does not support concurrency}} | ||
return data | ||
} | ||
|
||
let x = maybeData // expected-error{{'async' property access in a function that does not support concurrency}} | ||
_ = x | ||
|
||
if let maybeData { // expected-error{{'async' property access in a function that does not support concurrency}} | ||
return maybeData | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func takeAsync() async -> Int? { | ||
|
||
if let data = maybeData { // expected-error{{expression is 'async' but is not marked with 'await'}} | ||
// expected-note@-1{{property access is 'async'}} | ||
return data | ||
} | ||
|
||
let x = maybeData // expected-error{{expression is 'async' but is not marked with 'await'}} | ||
// expected-note@-1{{property access is 'async'}} | ||
_ = x | ||
|
||
if let maybeData { // expected-error{{expression is 'async' but is not marked with 'await'}} | ||
// expected-note@-1{{property access is 'async'}} | ||
return maybeData | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func illegalSyntax() async -> Int? { | ||
// This is NOT valid syntax and we reject it properly, | ||
// though we could try to could give a better message | ||
if let await maybeData { // expected-error{{unwrap condition requires a valid identifier}} | ||
// expected-error@-1{{pattern variable binding cannot appear in an expression}} | ||
// expected-warning@-2{{no 'async' operations occur within 'await' expression}} | ||
return maybeData // expected-error{{expression is 'async' but is not marked with 'await'}} | ||
// expected-note@-1{{property access is 'async'}} | ||
} | ||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm this doesn't quite seem right,
if let await result
is invalid, right? Looks like this fix-it logic is relying on the implicitness to detect the shorthand binding, maybe we need a bit to track this after all?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.
Hm true that’s wrong… I’ll look if there’s an easy fix… would like to prevent the crash asap but let me look at the bad fixit as well