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

Record types rejected as errors in constant initializer list #55247

Closed
eernstg opened this issue Mar 20, 2024 · 2 comments
Closed

Record types rejected as errors in constant initializer list #55247

eernstg opened this issue Mar 20, 2024 · 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

@eernstg
Copy link
Member

eernstg commented Mar 20, 2024

Consider the following program:

class A {
  final bool b;
  const A(r) : b = r is (int,) ? true : true; // Error.
}

const c1 = () is (int,); // OK.

typedef Id<X> = X;
const c2 = Id<(int,)>;

void main() {}

This program is accepted and executed with no errors by dart, but the analyzer rejects it as follows:

Invalid const value

which is reported at (int,), and the behavior is the same if we replace (int,) by a different record type, e.g., (int, int).

This is not an error, and it is indeed not reported for several other occurrences of (int,) as a type in a constant expression.

Hence, it looks like the analyzer emits a spurious error message in the combination of circumstances shown in the A constructor.

[Edit: I did not need the assert after all, changed the title accordingly.]

@eernstg eernstg added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-spec Issues with the analyzer's implementation of the language spec labels Mar 20, 2024
@eernstg
Copy link
Member Author

eernstg commented Mar 20, 2024

This is enough:

class A {
  final bool b;
  const A(r) : b = r is (int,); // Error.
}

And this:

typedef Id<X> = X;

class A {
  final b;
  const A(r) : b = Id<(int,)>; // Error.
}

@pq
Copy link
Member

pq commented Mar 20, 2024

@scheglov

@pq pq added the P2 A bug or feature request we're likely to work on label Mar 20, 2024
@eernstg eernstg changed the title Record types rejected as errors in constant assert. Record types rejected as errors in constant initializer list Mar 20, 2024
@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 16, 2024
@srawlins srawlins self-assigned this Apr 16, 2024
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

3 participants