[dart2wasm] Fix type substitution bug if records are involved

Fixes https://github.com/dart-lang/sdk/issues/54794

Change-Id: I13b4ae619fad7d7e00f4a17e199b85ebea4e6de7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349680
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
This commit is contained in:
Martin Kustermann 2024-02-01 11:38:58 +00:00 committed by Commit Queue
parent 3105c841d4
commit 2b396dd95a
2 changed files with 35 additions and 0 deletions

View file

@ -736,6 +736,16 @@ class _TypeUniverse {
assert(rootFunction == null);
return substituteInterfaceTypeParameter(
type.as<_InterfaceTypeParameterType>(), substitutions);
} else if (type.isRecord) {
final recordType = type.as<_RecordType>();
final fieldTypes = WasmArray<_Type>.filled(
recordType.fieldTypes.length, _literal<dynamic>());
for (int i = 0; i < recordType.fieldTypes.length; i++) {
fieldTypes[i] = substituteTypeArgument(
recordType.fieldTypes[i], substitutions, rootFunction);
}
return _RecordType(
recordType.names, fieldTypes, recordType.isDeclaredNullable);
} else if (type.isFunction) {
_FunctionType functionType = type.as<_FunctionType>();
bool isRoot = identical(type, rootFunction);

View file

@ -0,0 +1,25 @@
// Copyright (c) 2024, 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.
import 'package:expect/expect.dart';
main() {
final dynamic object = int.parse('1') == 1 ? Sub<int, String>() : 1;
Expect.isTrue(isBase<dynamic>(object));
Expect.isTrue(isBase<Object>(object));
Expect.isTrue(isBase<(dynamic, dynamic)>(object));
Expect.isTrue(isBase<(int, dynamic)>(object));
Expect.isTrue(isBase<(dynamic, String)>(object));
Expect.isTrue(isBase<(int, String)>(object));
Expect.isFalse(isBase<(String, dynamic)>(object));
Expect.isFalse(isBase<(dynamic, int)>(object));
}
bool isBase<T>(dynamic o) => o is Base<T>;
class Base<T> {}
class Sub<A, B> implements Base<(A, B)> {}