Skip to content
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

Analyzer allows expression with type void as expression switch case expression. #52136

Closed
lrhn opened this issue Apr 21, 2023 · 2 comments
Closed
Assignees
Labels
analyzer-language-patterns Issues with analyzer's support for the patterns language feature analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Apr 21, 2023

See dart-lang/language#2907 (comment) for context.

Example:

void main() => switch (1) {_ => print("ok")};

The CFE gives the error:

lib/main.dart:1:33:
Error: This expression has type 'void' and can't be used.
void main() => switch (1) {_ => print("ok")};
                                ^
Error: Compilation failed.

That is correct, because expressions of type void are only allowed in specific positions, and the expression of an expression switch case isn't on the list.
It didn't exist when the list was made, but we also haven't added the new position to that list.

The analyzer does not give the required error.

(We can choose to allow an expression switch case expression to have type void when the expression switch itself is allowed to have type void. We can't just say that it's OK for the case expression to have type void, because that void might get lost in a LUB with another branch's type. Unless a LUB containing at least one void always ends up as void. I don't know if it does, even when LUB'ed with, say, FutureOr<void>.)

@lrhn lrhn added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Apr 21, 2023
@srawlins srawlins added P2 A bug or feature request we're likely to work on analyzer-spec Issues with the analyzer's implementation of the language spec analyzer-language-patterns Issues with analyzer's support for the patterns language feature labels Apr 24, 2023
@scheglov scheglov self-assigned this Apr 25, 2023
copybara-service bot pushed a commit that referenced this issue Apr 25, 2023
Bug: #52136
Change-Id: I0a77a81d0a558e8b2450e91e6156d5fab03579a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298300
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
@scheglov
Copy link
Contributor

copybara-service bot pushed a commit that referenced this issue Apr 26, 2023
Bug: #52136
Change-Id: I3a3b8f45419c57deec77deae37cd5f98481debeb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298400
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
@leafpetersen
Copy link
Member

Unless a LUB containing at least one void always ends up as void. I don't know if it does, even when LUB'ed with, say, FutureOr<void>.

It does. See here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-language-patterns Issues with analyzer's support for the patterns language feature analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants