Closed
Description
When running the following program there is a type error in the assert()
.
test.dart
:
typedef T DoSpecialThing<T>(T thing);
String specialStringThing(String thing) => thing;
double specialDoubleThing(double thing) => thing;
class Property<T> {
Property(this._operation);
T doThing(T thing) => thing;
DoSpecialThing<T> get doSpecialThing => _operation;
DoSpecialThing<T> _operation;
}
Property<String> stringProperty = new Property<String>(specialStringThing);
Property<double> doubleProperty = new Property<double>(specialDoubleThing);
void main() {
List<Property> properties = [ stringProperty, doubleProperty ];
List values = [ "String value", 0.0 ];
for (int i = 0; i < properties.length; ++i) {
assert(properties[i].doSpecialThing(values[i]) == values[i]);
}
}
$ dart --enable-asserts --preview-dart-2 test.dart
Unhandled exception:
type '(String) => String' is not a subtype of type '(dynamic) => dynamic'
#0 main (file:///usr/local/google/home/zra/dart/dart2tests/test.dart)
#1 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#2 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
However, if doSpecialThing
is replaced with doThing
, which should have the same type(?), there is no type error.