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: Evaluation of constant expression using multiple libraries throws an exception #38658

Open
rebaz94 opened this issue Sep 30, 2019 · 5 comments

Comments

@rebaz94
Copy link

@rebaz94 rebaz94 commented Sep 30, 2019

There is an issue in the analysis server that said

Evaluation of this constant expression throws an exception

the code that produces is

_$AppDatabase(QueryExecutor e) : super(const SqlTypeSystem.withDefaults(), e)
Framework • revision e8517a434d (15 hours ago) • 2019-09-30 12:45:03 -0700
Engine • revision 1f454c7533
Tools • Dart 2.6.0 (build 2.6.0-dev.0.0 132bee48d0)

@simolus3

@simolus3
Copy link
Contributor

@simolus3 simolus3 commented Sep 30, 2019

EDIT: This is a divergence between the analyzer and the compiler that happens on Dart 2.6 and (in rare cases?) on Dart 2.5. See minimal repro that doesn't depend on anything but dart:core below.

Some more information on this: Here is the const constructor being called. All of entries in the list literal are simple constant constructors defined in this file.

I might be overlooking something, but I believe that this is an issue in the analyzer because

  1. it was introduced in Dart 2.5, and the changelog contains no entry that could affect how that code is evaluated
  2. It only affects some users
  3. Most times the error goes away after typing around in the generated file referenced in the issue description

Some users (me included) hit this issue, but I never managed to consistently reproduce it - the error always went away after restarting the analysis server or typing in the affected file. @rebaz94 said that restarting the analysis server did not fix the problem. We discussed this problem in simolus3/moor#154

@simolus3
Copy link
Contributor

@simolus3 simolus3 commented Sep 30, 2019

I get the same analysis error on Dart VM version: 2.6.0-dev.4.0 (Mon Sep 30 14:10:31 2019 +0200) on "linux_x64" on this line.

All the tests (which definitely run that line) pass though, so the analyzer rejects it but the frontend doesn't?

@simolus3
Copy link
Contributor

@simolus3 simolus3 commented Sep 30, 2019

Smallest repro I could find: Create two Dart files, base.dart and repro.dart:

// base.dart
class Base<T> {
  const Base();
}

class A extends Base<String> {
  const A();
}

class Repro {
  final List<Base> bases;

  const Repro(this.bases);

  const Repro.foo() : this(const [A()]);
}

and

// repro.dart
import 'base.dart';

void main() {
  const Repro.foo(); // "evaluation of this constant expression throws exception"
}

Notably, the error does not occur when Repro is declared in the same file as the main method.

Edit I've fixed the typo.

Possibly related to #38659?

@eernstg
Copy link
Member

@eernstg eernstg commented Oct 1, 2019

Probably:

void main() {
  const Repro.foo();
}

That causes the error with an analyzer from commit 0242dea, and there's no error when the two libraries are combined into one library.

@JohnGalt1717
Copy link

@JohnGalt1717 JohnGalt1717 commented Aug 31, 2020

In my case the error was that the package had an assert preventing null and because the value was optional in the child class parameter list, it threw the non-descript error message.

At runtime on web it threw an error without a message and on ios/android it throws the proper assert message.

@srawlins srawlins added the P3 label Jan 28, 2021
@srawlins srawlins changed the title Analyzer: Evaluation of constant expression throws an exception Analyzer: Evaluation of constant expression using multiple libraries throws an exception Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants