Closed
Description
Example:
void main() {
const ex3 = ExInt(3);
const ex4 = ExInt(4);
const l3 = [ex3];
const l4 = [ex4];
const l34i = [ex3 as int, ... l4 as List<int>]; // Works
const l43 = [ex4, ex3]; // Works
// Info: Expected constant '3' to be of type 'ExInt', but was of type 'int'.
const l3s4 = [ex3, ... l4]; // Fails to compile.
// ^
// Info: Expected constant '4' to be of type 'ExInt', but was of type 'int'.
const ls43 = [... l4, ex3]; // Fails to compile.
// ^
// Info: Expected constant '3' to be of type 'ExInt', but was of type 'int'.
const ls3s4 = [... l3, ... l4]; // Fails to compile.
// ^
}
extension type const ExInt(int _) implements int {}
Both VM and dart2js give similar error messages (dart2js uses web numbers, so "constant '3.0'" and "type 'double'").
It seems the static and runtime types gets mixed up somewhere along the way, to the point where we likely try to check that the constant value is a subtype of its static type. Any time we check actual values, we should use the extension-erased static type.