Skip to content

Commit 68229c4

Browse files
mkustermannCommit Queue
authored and
Commit Queue
committed
[dart2wasm] Make is/as-checker helpers be used even if operand type is not InterfaceType
Right now the optimized is/as-checkers are only used when the operand type is an [InterfaceType]. That means they don't get used for e.g. dynamic obj; T obj2; obj is String obj2 is List<dynamic>; But we can use the is/as-checkers on any operand type as long as the type we test against is an [InterfaceType] without arguments or where the type arguments are equivalent to defaults-to-bounds (i.e. require no checking). Issue #55516 Change-Id: I1adff52b3d880c37c344edb0c42ffd454d7b1164 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371124 Reviewed-by: Ömer Ağacan <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent 6d185d2 commit 68229c4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pkg/dart2wasm/lib/types.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,14 @@ class Types {
484484
InterfaceType? _canUseTypeCheckHelper(
485485
DartType testedAgainstType, DartType operandType) {
486486
// The is/as check helpers are for cid-range checks of interface types.
487-
if (testedAgainstType is! InterfaceType || operandType is! InterfaceType) {
488-
return null;
489-
}
487+
if (testedAgainstType is! InterfaceType) return null;
490488

491489
if (_hasOnlyDefaultTypeArguments(testedAgainstType)) {
492490
return testedAgainstType;
493491
}
494492

495-
if (_staticTypesEnsureTypeArgumentsMatch(testedAgainstType, operandType)) {
493+
if (operandType is InterfaceType &&
494+
_staticTypesEnsureTypeArgumentsMatch(testedAgainstType, operandType)) {
496495
// We only need to check whether the nullability and the class itself fits
497496
// (the [testedAgainstType] arguments are guaranteed to fit statically)
498497
final parameters = testedAgainstType.classNode.typeParameters;

0 commit comments

Comments
 (0)