mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 09:43:08 +00:00
[dart2wasm] Only share type parameter fields if nullability allows
Closes https://github.com/dart-lang/sdk/issues/55741 Change-Id: I1e542041496d07714431ed40871031a117030736 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366940 Reviewed-by: Ömer Ağacan <omersa@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
parent
c91b5edf1c
commit
e6e9b4e595
3 changed files with 44 additions and 4 deletions
|
@ -318,8 +318,10 @@ class ClassInfoCollector {
|
|||
: cls.implementedTypes.single;
|
||||
for (TypeParameter parameter in cls.typeParameters) {
|
||||
for (int i = 0; i < supertype.typeArguments.length; i++) {
|
||||
DartType arg = supertype.typeArguments[i];
|
||||
if (arg is TypeParameterType && arg.parameter == parameter) {
|
||||
DartType superTypeArg = supertype.typeArguments[i];
|
||||
if (superTypeArg is TypeParameterType &&
|
||||
superTypeArg.parameter == parameter &&
|
||||
superTypeArg.nullability != Nullability.nullable) {
|
||||
typeParameterMatch[parameter] = superInfo.cls!.typeParameters[i];
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -149,8 +149,10 @@ class _WasmTransformer extends Transformer {
|
|||
}
|
||||
for (int i = 0; i < cls.typeParameters.length; i++) {
|
||||
TypeParameter parameter = cls.typeParameters[i];
|
||||
DartType arg = supertype.typeArguments[i];
|
||||
if (arg is! TypeParameterType || arg.parameter != parameter) {
|
||||
DartType superTypeArg = supertype.typeArguments[i];
|
||||
if (superTypeArg is! TypeParameterType ||
|
||||
superTypeArg.parameter != parameter ||
|
||||
superTypeArg.nullability == Nullability.nullable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
36
tests/language/regression_55741_test.dart
Normal file
36
tests/language/regression_55741_test.dart
Normal file
|
@ -0,0 +1,36 @@
|
|||
// 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';
|
||||
|
||||
final kTrue = int.parse('1') == 1;
|
||||
|
||||
void main() {
|
||||
final base = kTrue ? Base<String>('a') : 1;
|
||||
final baseNullable = kTrue ? Base<String?>('a') : 1;
|
||||
final sub = kTrue ? Sub<String>('a') : 1;
|
||||
final subNullable = kTrue ? Sub<String?>('a') : 1;
|
||||
|
||||
Expect.isTrue(base is Base<String>, 'is Base<String>');
|
||||
Expect.isTrue(base is Base<String?>, 'is Base<String?>');
|
||||
Expect.isTrue(baseNullable is! Base<String>, 'is! Base<String>');
|
||||
Expect.isTrue(baseNullable is Base<String?>, 'is Base<String?>');
|
||||
Expect.isTrue(sub is Sub<String>, 'is Sub<String>');
|
||||
Expect.isTrue(sub is Sub<String?>, 'is Sub<String?>');
|
||||
Expect.isTrue(subNullable is! Sub<String>, 'is! Sub<String>');
|
||||
Expect.isTrue(subNullable is Sub<String?>, 'is Sub<String?>');
|
||||
Expect.isTrue(sub is! Base<String>, 'is! Base<String>');
|
||||
Expect.isTrue(sub is Base<String?>, 'is Base<String?>');
|
||||
Expect.isTrue(subNullable is! Base<String>, 'is! Base<String>');
|
||||
Expect.isTrue(subNullable is Base<String?>, 'is Base<String?>');
|
||||
}
|
||||
|
||||
class Base<T> {
|
||||
Base(this.data);
|
||||
final T data;
|
||||
}
|
||||
|
||||
class Sub<T> extends Base<T?> {
|
||||
Sub(super.data);
|
||||
}
|
Loading…
Reference in a new issue