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 fails to report "expression has type void and cannot be used" for record argument #53769

Closed
stereotype441 opened this issue Oct 16, 2023 · 2 comments
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. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@stereotype441
Copy link
Member

The following code is accepted by the analyzer but rejected by the CFE:

void f() {}

main() {
  var x = (1, f());
  print(x);
}

The CFE reports:

../../tmp/proj/test.dart:4:15: Error: This expression has type 'void' and can't be used.
  var x = (1, f());
              ^

I believe the CFE behavior is correct.

@stereotype441 stereotype441 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) 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 Oct 16, 2023
@eernstg
Copy link
Member

eernstg commented Oct 17, 2023

That's tricky! ;-) If we consider the initializing expression to have type (int, void) and consider (1, f()) to be an expression where 1 is used to initialize the int field of the record and f() is used to initialize the void field (similarly a constructor invocation) then it shouldn't be worse than this:

void f() {}
void g(int i, void v) {}
var _ = g(1, f()); // OK.

@srawlins
Copy link
Member

Duplicate of #52759

@srawlins srawlins marked this as a duplicate of #52759 Oct 17, 2023
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. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants