[ddc] Fix covariant bound checks with new types

Issue: https://github.com/dart-lang/sdk/issues/48585
Change-Id: I7a5d9c412696ea038af8320734790456d4e2880a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306914
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
This commit is contained in:
Nicholas Shahan 2023-06-02 21:56:07 +00:00 committed by Commit Queue
parent 4f2f3405fb
commit 00d63e7bf9
2 changed files with 12 additions and 4 deletions

View file

@ -745,9 +745,6 @@ cast(obj, type) {
///
/// Will produce a warning/error (if enabled) when the subtype passes but would
/// fail in sound null safety.
///
/// Currently only called from _checkAndCall to test type arguments applied to
/// dynamic method calls.
// TODO(48585) Revise argument types after removing old type representation.
@notNull
bool _isSubtypeWithWarning(@notNull t1, @notNull t2) {

View file

@ -1190,7 +1190,18 @@ bool isType(obj) => JS('', '#[#] === #', obj, _runtimeType, Type);
void checkTypeBound(
@notNull Object type, @notNull Object bound, @notNull String name) {
if (!isSubtypeOf(type, bound)) {
bool validSubtype;
if (JS_GET_FLAG('NEW_RUNTIME_TYPES')) {
validSubtype = compileTimeFlag('soundNullSafety')
// Check subtype directly in sound mode.
? rti.isSubtype(JS_EMBEDDED_GLOBAL('', RTI_UNIVERSE),
JS<rti.Rti>('!', '#', type), JS<rti.Rti>('!', '#', bound))
// Check subtype but issue warnings/errors in weak mode.
: _isSubtypeWithWarning(type, bound);
} else {
validSubtype = isSubtypeOf(type, bound);
}
if (!validSubtype) {
throwTypeError('type `$type` does not extend `$bound` of `$name`.');
}
}