23a289417d
When casting a getter return value that requires a covariance check, the CFE inserts an AsExpression where both the operand type and tested-against type are statically identical (the instantiated member return type, e.g. Callable<void Function(num)>). The types.dart optimizer previously assumed that because the static types matched, the runtime type arguments must also match, and optimized away the type-argument checks. However, in a covariance check, the dynamic value returned is a supertype (e.g. Callable<void Function(int)>) due to class parameter covariance. This change safely rewrites the static operand type of a covariance check by preserving the InterfaceType structure but using calculateBounds to rewrite its type arguments to their upper bounds (falling back to Object? or Object for non-interface types). This allows us to keep class-check optimizations active while remaining sound. TEST=tests/language/covariant/callable_class_field_getter_test.dart Fixes https://github.com/dart-lang/sdk/issues/53091 Change-Id: Ia64ea90b1bad2f7c1dab81cc3385103507b97b3e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508425 Reviewed-by: Martin Kustermann <kustermann@google.com> Auto-Submit: Kevin Moore <kevmoo@google.com> Commit-Queue: Kevin Moore <kevmoo@google.com>