-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
customer-dart-2front-end-kernellegacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.
Description
The following code contains an implicit downcast of a parameter default value:
const List<Object> x = ...;
f({List<int> y: x}) {} // implicit downcast from `List<Object>` to `List<int>`.Depending on the value of the constant x, this might or might not lead to an error. Note that due to the exisence of fromEnvironment const constructors, the front end doesn't do constant evaluation, so it can't tell whether an error should occur--detecting the error is postponed to runtime (as it is with other implicit downcasts). Currently the front end handles this by generating the following kernel representation:
static const field core::List<core::Object> x = ...;
static method f({core::List<core::int> y = self::x as{TypeError} core::List<core::int>}) → void {}
This seems undesirable, because:
- compile-time constants are not normally allowed to contain
asexpressions - it seems a little strange that errors involving "constants" would not be detected until runtime
- it's not clear when the runtime error is expected to occur (should it occur at the time of the call to
f? At the time of execution of any method which refers tof? When the program starts?). This makes it hard to write effective tests for this scenario.
Metadata
Metadata
Assignees
Labels
customer-dart-2front-end-kernellegacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.