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

Bogus analyzer error for late field initializer referencing super? #46850

Closed
jamesderlin opened this issue Aug 8, 2021 · 2 comments
Closed
Assignees
Labels
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

Comments

@jamesderlin
Copy link
Contributor

jamesderlin commented Aug 8, 2021

late member variables are able to use field initializers that reference this, so I don't see why super should be any different. Given the following code:

class Base {
  final int value = 42;
}

class Derived extends Base {
  late int _value = super.value;

  @override
  int get value => _value;
}

void main() {
  var derived = Derived();
  print(derived.value);
}

the analyzer prints:

  error • example.dart:6:21 • Invalid context for 'super' invocation. •
          super_in_invalid_context

However, there seems to be no issue when actually running the above code. Regardless of whether super should be allowed here, this behavior is inconsistent.

I've observed the analyzer error in both DartPad (Flutter 2.2.3 Dart SDK 2.13.4) and when running dart analyze (Dart SDK version: 2.13.4 (stable)).

@vsmenon vsmenon added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Aug 8, 2021
@jcollins-g jcollins-g added P1 A high priority bug; for example, a single project is unusable or has many test failures P2 A bug or feature request we're likely to work on and removed P1 A high priority bug; for example, a single project is unusable or has many test failures labels Aug 10, 2021
@jcollins-g
Copy link
Contributor

jcollins-g commented Aug 10, 2021

// ignore: super_in_invalid_context seems to help, so marking as P2 (invalid analysis error on edge case with workaround)

@scheglov scheglov self-assigned this Sep 10, 2021
@scheglov
Copy link
Contributor

dart-bot pushed a commit that referenced this issue Sep 13, 2021
Bug: #46850
Change-Id: I90560e7e9d75ef450b47d584e0fa0f35123e0e61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213029
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
Projects
None yet
Development

No branches or pull requests

4 participants