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 report element from deferred import used as annotation argument #45418

Closed
srawlins opened this issue Mar 22, 2021 · 2 comments
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. P3 A lower priority bug or feature request

Comments

@srawlins
Copy link
Member

Take these two files, a.dart:

const x = 0;

and b.dart

import 'a.dart' deferred as a;
class C { const C(int i); }
@C(a.x) main () {}

Analyzer reports nothing wrong, but CFE/VM complain:

b.dart:3:4: Error: 'a' can't be used in a constant expression because it's marked as 'deferred' which means it isn't available until loaded.
Try moving the constant from the deferred library, or removing 'deferred' from the import.

@C(a.x) main () {}
   ^
b.dart:3:2: Error: Constant evaluation error:
@C(a.x) main () {}
 ^
b.dart:3:6: Context: 'a' can't be used in a constant expression because it's marked as 'deferred' which means it isn't available until loaded.
Try moving the constant from the deferred library, or removing 'deferred' from the import.

@C(a.x) main () {}
     ^
b.dart:3:9: Context: While analyzing:
@C(a.x) main () {}
        ^
@srawlins srawlins added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request analyzer-spec Issues with the analyzer's implementation of the language spec labels Mar 22, 2021
dart-bot pushed a commit that referenced this issue Mar 22, 2021
…gument

Bug: #45418
Change-Id: I6332caab0ecc5604d0631f4669314355f699b720
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192485
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
@lfkdsk
Copy link
Contributor

lfkdsk commented Apr 23, 2021

It seems like that ConstEvalDeferredLibrary's corresponding analyzer code is NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LIBRARY.

ConstEvalDeferredLibrary:
  template: >
    '#nameOKEmpty' can't be used in a constant expression because it's marked as
    'deferred' which means it isn't available until loaded.
  tip: >
    Try moving the constant from the deferred library, or removing 'deferred'
    from the import.
  analyzerCode: NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LIBRARY

@lfkdsk
Copy link
Contributor

lfkdsk commented Apr 23, 2021

try to fix with: #45806

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. P3 A lower priority bug or feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants