Skip to content

Commit

Permalink
[dart2js] Fix type inference for record accessses on invalid indices.
Browse files Browse the repository at this point in the history
Bug: 52438
Change-Id: Ic180e181142f6a33e9915f13890d9a3825a5ec0c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304380
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
  • Loading branch information
natebiggs authored and Commit Queue committed May 18, 2023
1 parent 3af9eb5 commit 327a680
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/compiler/lib/src/inferrer/typemasks/masks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,15 @@ class CommonMasks with AbstractValueDomain {

@override
AbstractValue getGetterTypeInRecord(AbstractValue value, String getterName) {
final type = value is RecordTypeMask
? value.types[value.shape.indexOfGetterName(getterName)]
: null;
return type ?? dynamicType;
if (value is RecordTypeMask) {
final getterIndex = value.shape.indexOfGetterName(getterName);
// Generated code can sometimes contain record accesses for invalid
// getters.
if (getterIndex >= 0) {
return value.types[getterIndex];
}
}
return dynamicType;
}

@override
Expand Down
15 changes: 15 additions & 0 deletions tests/web/regress/issue/52438_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Switches geenrate record accesses on non-existent fields. These accesses
// should be guarded by a type check but Dart2JS does not always promote
// correctly after the type check.

void main() {
Object r = (1, 2);
switch (r) {
case (int _, int _, int c):
print('Skip, no match');
}
}

0 comments on commit 327a680

Please sign in to comment.