-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
legacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.
Description
Dart 3.3.0
Consider this snippet:
final class Foo<T> {
const Foo(this.bar);
final T bar;
}
List<Foo> get foos1 => const [Foo(1), Foo("2")];
List get foos2 => const [Foo(1), Foo("2")];
void main() {
final List<Foo> wrong = foos1;
print(wrong[0].runtimeType);
final List<Foo> right = foos2.cast<Foo>().toList();
print(right[0].runtimeType);
final List alsoRight = foos2;
print(alsoRight[0].runtimeType);
}
Output:
Foo<dynamic>
Foo<int>
Foo<int>
I don't think there is a valid reason for foos1
's elements losing their type.
Second example:
final class Foo<T> {
const Foo(this.bar);
final T bar;
}
void main() {
Foo<dynamic> a = Foo(1);
print(a.runtimeType);
print(a.bar.runtimeType);
dynamic b = Foo(1);
print(b.runtimeType);
print(b.bar.runtimeType);
}
In the above example bar
's type is never forgotten, but a
is demoted to Foo<dynamic>
even tho the instance is of type Foo<int>
.
Metadata
Metadata
Assignees
Labels
legacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.