Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save timnew/c52700c7b4543d216ad1f1324a96ef3e to your computer and use it in GitHub Desktop.
Save timnew/c52700c7b4543d216ad1f1324a96ef3e to your computer and use it in GitHub Desktop.
Unexpected covariance type inference
abstract class Stated<T> {
const Stated._();
factory Stated.idle() => const _Idle();
const factory Stated.value(T value) = _Value;
Type get valueType => T;
}
class _Idle<T> extends Stated<T>{
const _Idle(): super._();
}
class _Value<T> extends Stated<T>{
final T value;
const _Value(this.value): super._();
}
void main(){
final Stated<String> stated = Stated.idle();
print(stated.valueType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment