dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.25k stars 1.58k forks source link

Analyzer doesn't recognize constants in NNBD libraries as const in opted out libraries #40218

Closed leafpetersen closed 4 years ago

leafpetersen commented 4 years ago

test5.dart:

class ConstClass {
  const ConstClass();
}
const int constInt = 3;
const ConstClass constClass = ConstClass();

test4.dart:

import "test5.dart";

Class D {
  foo({int a = constInt, ConstClass c = constClass}) {}
}
void main() {}
leafp-macbookpro:language leafp$ ~/src/dart-repo/sdk/xcodebuild/ReleaseX64NNBD/dart-sdk/bin/dartanalyzer --enable-experiment=non-nullable  ~/tmp/test4.dart
Analyzing /Users/leafp/tmp/test4.dart...
  error • The default value of an optional parameter must be constant. • /Users/leafp/tmp/test4.dart:7:16 • non_constant_default_value
  error • The default value of an optional parameter must be constant. • /Users/leafp/tmp/test4.dart:7:41 • non_constant_default_value
2 errors found.

cc @scheglov cc @vsmenon @sigmundch this is one of the remaining dart:io issues

scheglov commented 4 years ago

https://dart-review.googlesource.com/c/sdk/+/132405 fixed this.