-
Notifications
You must be signed in to change notification settings - Fork 228
Open
Labels
requestRequests to resolve a particular developer problemRequests to resolve a particular developer problem
Description
There's some weird inconsistencies in the way types can be used in a library if those types come from a deferred import:
import 'def.dart' deferred as D;
dynamic dynamicValue;
main() async {
await D.loadLibrary();
// -----------------
// Question 1:
// -----------------
print(D.Foo); // No compile-time-error: Can use as type literal
print(<D.Foo>[]); // compile-time-error: Cannot use in type expressions
// => Why is one valid the other invalid.
// -----------------
// Question 2:
// -----------------
// I can create variables with `D.Foo` type this way:
var variableWithFooType = D.makeFoo(); // No compile-time-error, implicit `D.Foo` type
variableWithFooType = dynamicValue; // No compile-time-error, implicit `as D.Foo` cast.
// But I cannot do either of these:
D.Foo variableWithFooType = D.makeFoo(); // compile-time-error: explicit `D.Foo` type
variableWithFooType = dynamicValue as D.Foo; // compile-time-error: explicit `as D.Foo` cast
}with def.dart
class Foo {}
Foo makeFoo() => Foo();Metadata
Metadata
Assignees
Labels
requestRequests to resolve a particular developer problemRequests to resolve a particular developer problem