The following code:
import 'package:test/test.dart';
class Provider {
const Provider();
}
class Module {
final List<Provider> providers;
const Module(this.providers);
}
const aGoodModule = const Module(const [
const Provider(),
]);
const listOfThings = const [
const [],
const Provider(),
];
const aBadModule = const Module(listOfThings);
void main() {
test('$aBadModule should be invalid', () {
expect(aBadModule.providers, const isInstanceOf<List<Provider>>());
});
}
... throws the following very scary error message:
Unhandled exception:
'file:///Users/matanl/github/dart.scratch/dart2_const_downcast/test/dart2_const_downcast_test.dart': error: Not a constant expression: _ImmutableList len:2 is not an instance of Type: class 'List', args:[TypeArguments: (@0x11e2dc031 H39565ba6) [Type: class 'Provider']]'file:///Users/matanl/github/dart.scratch/dart2_const_downcast/test/dart2_const_downcast_test.dart': error: line 26 pos 10: Not a constant expression.
test('$aBadModule should be invalid', () {
... this is an error (listOfThings is not a List<Provider>), but it's very hard to figure out here:
_ImmutableList isn't something I wrote
- This seems to not have the better error messages I've seen elsewhere
- This seems to leak internals of the VM (
TypeArguments: (@0x11e2dc031 H39565ba6)).
I'll file a separate bug on the analyzer/DDC - I wouldn't have gotten that far if the IDE warned me.
The following code:
... throws the following very scary error message:
... this is an error (
listOfThingsis not aList<Provider>), but it's very hard to figure out here:_ImmutableListisn't something I wroteTypeArguments: (@0x11e2dc031 H39565ba6)).I'll file a separate bug on the analyzer/DDC - I wouldn't have gotten that far if the IDE warned me.