Skip to content

unhappy analyzer with super params and default value in base class #48727

@goderbauer

Description

@goderbauer

I found one more case while enabling this feature in Flutter. In dart 2.17.0-263.0.dev the analyzer is unhappy with the code below (see errors in comments), but it executes fine on the VM. I believe the code is valid and the analyzer is complaining incorrectly.

class PopupMenuItem<T> {
  const PopupMenuItem({
    this.enabled = true,
  });

  final bool enabled;
}

class CheckedPopupMenuItem<T> extends PopupMenuItem<T> {
  const CheckedPopupMenuItem({
    super.enabled,
  });
}

// 🔥 error: A value of type 'Null' can't be assigned to a parameter of type 'bool' in a const constructor. (const_constructor_param_type_mismatch at [test] lib/pure_dart.dart:17)
// 🔥 error: Evaluation of this constant expression throws an exception. (const_eval_throws_exception at [test] lib/pure_dart.dart:16)
final CheckedPopupMenuItem menuItemType = const CheckedPopupMenuItem<String>();

void main() {
  print(menuItemType.enabled);
}

Metadata

Metadata

Assignees

Labels

P1A high priority bug; for example, a single project is unusable or has many test failuresdart-model-analyzer-specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions