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 does not detect usage of void in record #52759

Closed
julemand101 opened this issue Jun 22, 2023 · 2 comments
Closed

Analyzer does not detect usage of void in record #52759

julemand101 opened this issue Jun 22, 2023 · 2 comments
Assignees
Labels
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

@julemand101
Copy link
Contributor

After seeing dart-lang/language#3157 it looks like the analyzer currently fails to report the usage of void in a Record while the compiler is not quite happy about such a thing.

The following piece of code is allowed by the analyzer but fails when trying to run with VM or compile to an exe:

void main() {
  void test;
  print((test,));
  processLifecycle();
}

void processLifecycle() => (create(), update(), dispose());

void create() {}
void update() {}
void dispose() {}

Error from compile (nearly the same output when running with dart):

> dart compile exe .\stack1.dart
stack1.dart:3:10: Error: This expression has type 'void' and can't be used.
  print((test,));
         ^
stack1.dart:7:29: Error: This expression has type 'void' and can't be used.
void processLifecycle() => (create(), update(), dispose());
                            ^
stack1.dart:7:39: Error: This expression has type 'void' and can't be used.
void processLifecycle() => (create(), update(), dispose());
                                      ^
stack1.dart:7:49: Error: This expression has type 'void' and can't be used.
void processLifecycle() => (create(), update(), dispose());
                                                ^
Error: AOT compilation failed
Generating AOT kernel dill failed!

Dart SDK Version:

Dart SDK version: 3.1.0-227.0.dev (dev) (Sun Jun 18 18:21:21 2023 -0700) on "windows_x64"
@lrhn
Copy link
Member

lrhn commented Jun 22, 2023

As specified, a void expression can only occur in a selected few syntactic positions. The records feature did not add any new positions, so the "record field value expression" position should not allow a void expression.

(The record specification should probably have said so explicitly, because it's so easy for an implementor to forget otherwise, they actually have to write a check for every position where void is disallowed, and do nothing where it's allowed. Let's remember that for future new syntactic positions.)

That said, we allow void expression in argument position for a void typed parameter, and if we want records to match argument lists, that'd be an argument for allowing this. (Or for disallowing it in argumyzeent position. Personal opinion: The only expresssions allowed in a void context are those assignable to Null.)

We're also currently allowing void expressions incorrectly in other places too:

void main() {
  var list = [print("OK"), print("NOT!")];
}

This creates a List<void>. A void expresssion in element position is not allowed by the specification, but it's not caught by either CFE or analyzer.

(We should check all the positions.)

@lrhn lrhn added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jun 22, 2023
@bwilkerson
Copy link
Member

@scheglov

@keertip keertip added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P2 A bug or feature request we're likely to work on labels Jun 22, 2023
@srawlins srawlins added the analyzer-spec Issues with the analyzer's implementation of the language spec label Oct 17, 2023
@srawlins srawlins self-assigned this Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

5 participants