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

Spurious analyzer diagnostic about a Null value when using a function expression in a const context #47603

Closed
natebosch opened this issue Nov 2, 2021 · 2 comments
Labels
analyzer-constants 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

@natebosch
Copy link
Member

class C {
  final void Function() c;
  const C(this.c);
}

void main() {
  const C(() {});
}

Analyzer will report 2 errors, one of which is expected, and one which is distracting and confusing.

Expected error:

Arguments of a constant creation must be constant expressions.

Unexpected error:

A value of type 'Null' can't be assigned to a parameter of type 'void Function()' in a const constructor.
@natebosch natebosch added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Nov 2, 2021
@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Nov 16, 2021
@bwilkerson bwilkerson added the P2 A bug or feature request we're likely to work on label Apr 25, 2022
@srawlins
Copy link
Member

Weird, still an issue.

copybara-service bot pushed a commit that referenced this issue Jul 25, 2023
…onstant value.

evaluateConstructorCall now returns a Constant, which means evaluation may be cut early in some places if there's an error. However, some code generators rely on _InstanceCreationEvaluator to complete, and so there's no _major_ changes to the design right now (and some small additions to avoid breaking many tests).

This CL is just the framework for the "return Constant" design and will be the base for reporting better errors in constructor invocations.

These changes already show that we cut some amount of over-reporting in our existing language and unit tests, which is a step in the right direction.

Bug: #47603, #47351, #49389

Change-Id: I5ba7f1282658884c18a32d5e98c7804bbfeac0f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312347
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
@kallentu
Copy link
Member

Fixed after ba00516.

copybara-service bot pushed a commit that referenced this issue Jul 26, 2023
… be assigned to a parameter' overreporting in the const evaluator.

The constant evaluator now handles invalid types better and won't overreport this nonsensical error.

Bug: #47603, #47351, #49389
Change-Id: I63c253d2177c2b8c259c364e83753653eac1cae0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312707
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-constants 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