Closed
Description
I noticed simply tearing off a field that contains a function from a generic class produces an AsExpression
node when the function uses the generic type argument in the contravariant position. The evaluation of TypeEnvironment.isSubtypeOf(from, to, SubtypeCheckMode.withNullabilities)
evaluates to true
but since the cast is marked with the TypeError
and CovarianceCheck
flags ddc will emit a cast that always seems to pass.
Is this cast necessary and is there an example that would cause this cast to fail?
class GenericType<T> {
var genericFunction = (T t) => null;
}
main() {
var generic = GenericType<int>();
var tearOff = generic.genericFunction;
}
main = tes::main;
library from "org-dartlang-app:/test_02.dart" as tes {
class GenericType<T extends core::Object? = dynamic> extends core::Object {
field (tes::GenericType::T%) → core::Null? genericFunction = (tes::GenericType::T% t) → core::Null? => null;
synthetic constructor •() → tes::GenericType<tes::GenericType::T%>
: super core::Object::•()
;
}
static method main() → dynamic {
tes::GenericType<core::int> generic = new tes::GenericType::•<core::int>();
(core::int) → core::Null? tearOff = generic.{tes::GenericType::genericFunction} as{TypeError,CovarianceCheck,ForNonNullableByDefault} (core::int) → core::Null?;
}
}