Skip to content

Commit eada9fa

Browse files
committed
Issue 42605. Do LEGACY_ERASURE when checking inferred mixin type arguments.
Bug: #42605 Change-Id: I58d27352e770ce63fabc0da2c07920dbadb8af11 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153482 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent ec30a30 commit eada9fa

File tree

4 files changed

+112
-10
lines changed

4 files changed

+112
-10
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ typedef WorkToWaitAfterComputingResult = Future<void> Function(String path);
9191
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
9292
class AnalysisDriver implements AnalysisDriverGeneric {
9393
/// The version of data format, should be incremented on every format change.
94-
static const int DATA_VERSION = 104;
94+
static const int DATA_VERSION = 105;
9595

9696
/// The length of the list returned by [_computeDeclaredVariablesSignature].
9797
static const int _declaredVariablesSignatureLength = 4;

pkg/analyzer/lib/src/dart/element/type_system.dart

+15-6
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,16 @@ abstract class TypeSystem implements public.TypeSystem {
241241
var substitution = Substitution.fromPairs(typeParameters, inferredTypes);
242242

243243
for (int i = 0; i < srcTypes.length; i++) {
244-
if (substitution.substituteType(srcTypes[i]) != destTypes[i]) {
244+
var srcType = substitution.substituteType(srcTypes[i]);
245+
var destType = destTypes[i];
246+
if (isNonNullableByDefault) {
247+
// TODO(scheglov) waiting for the spec
248+
// https://github.com/dart-lang/sdk/issues/42605
249+
} else {
250+
srcType = toLegacyType(srcType);
251+
destType = toLegacyType(destType);
252+
}
253+
if (srcType != destType) {
245254
// Failed to find an appropriate substitution
246255
return null;
247256
}
@@ -345,6 +354,11 @@ abstract class TypeSystem implements public.TypeSystem {
345354
return type;
346355
}
347356

357+
DartType toLegacyType(DartType type) {
358+
if (isNonNullableByDefault) return type;
359+
return NullabilityEliminator.perform(typeProvider, type);
360+
}
361+
348362
/// Tries to promote from the first type from the second type, and returns the
349363
/// promoted type if it succeeds, otherwise null.
350364
DartType tryPromoteToType(DartType to, DartType from);
@@ -1427,11 +1441,6 @@ class TypeSystemImpl extends TypeSystem {
14271441
return RuntimeTypeEqualityHelper(this).equal(T1, T2);
14281442
}
14291443

1430-
DartType toLegacyType(DartType type) {
1431-
if (isNonNullableByDefault) return type;
1432-
return NullabilityEliminator.perform(typeProvider, type);
1433-
}
1434-
14351444
/// Merges two types into a single type.
14361445
/// Compute the canonical representation of [T].
14371446
///

pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analyzer/dart/analysis/features.dart';
66
import 'package:analyzer/dart/ast/ast.dart';
7+
import 'package:analyzer/dart/element/null_safety_understanding_flag.dart';
78
import 'package:analyzer/src/context/context.dart';
89
import 'package:analyzer/src/dart/analysis/session.dart';
910
import 'package:analyzer/src/dart/element/class_hierarchy.dart';
@@ -108,9 +109,13 @@ class ResynthesizeAst2Test extends ResynthesizeTestStrategyTwoPhase
108109
LinkedBundleContext(elementFactory, sdkBundle),
109110
);
110111

111-
var linkResult = link(
112-
elementFactory,
113-
inputLibraries,
112+
var linkResult = NullSafetyUnderstandingFlag.enableNullSafetyTypes(
113+
() {
114+
return link(
115+
elementFactory,
116+
inputLibraries,
117+
);
118+
},
114119
);
115120

116121
elementFactory.addBundle(

pkg/analyzer/test/src/summary/resynthesize_common.dart

+88
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import 'package:analyzer/src/generated/source.dart';
1616
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
1717
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
1818
import 'package:test/test.dart';
19+
import 'package:test_reflective_loader/test_reflective_loader.dart';
1920

2021
import 'element_text.dart';
2122
import 'test_strategies.dart';
@@ -9348,6 +9349,93 @@ mixin M on Object {
93489349
''');
93499350
}
93509351

9352+
test_mixin_inference_legacy() async {
9353+
var library = await checkLibrary(r'''
9354+
class A<T> {}
9355+
mixin M<U> on A<U> {}
9356+
class B extends A<int> with M {}
9357+
''');
9358+
checkElementText(
9359+
library,
9360+
r'''
9361+
class A<T> {
9362+
}
9363+
class B extends A<int*>* with M<int*>* {
9364+
synthetic B();
9365+
}
9366+
mixin M<U> on A<U*>* {
9367+
}
9368+
''',
9369+
annotateNullability: true);
9370+
}
9371+
9372+
test_mixin_inference_nullSafety() async {
9373+
featureSet = enableNnbd;
9374+
var library = await checkLibrary(r'''
9375+
class A<T> {}
9376+
mixin M<U> on A<U> {}
9377+
class B extends A<int> with M {}
9378+
''');
9379+
checkElementText(
9380+
library,
9381+
r'''
9382+
class A<T> {
9383+
}
9384+
class B extends A<int> with M<int> {
9385+
synthetic B();
9386+
}
9387+
mixin M<U> on A<U> {
9388+
}
9389+
''',
9390+
annotateNullability: true);
9391+
}
9392+
9393+
test_mixin_inference_nullSafety_mixed_inOrder() async {
9394+
featureSet = enableNnbd;
9395+
addLibrarySource('/a.dart', r'''
9396+
class A<T> {}
9397+
mixin M<U> on A<U> {}
9398+
''');
9399+
var library = await checkLibrary(r'''
9400+
// @dart = 2.8
9401+
import 'a.dart';
9402+
class B extends A<int> with M {}
9403+
''');
9404+
checkElementText(
9405+
library,
9406+
r'''
9407+
import 'a.dart';
9408+
class B extends A<int*>* with M<int*>* {
9409+
synthetic B();
9410+
}
9411+
''',
9412+
annotateNullability: true);
9413+
}
9414+
9415+
@FailingTest(reason: 'Out-of-order inference is not specified yet')
9416+
test_mixin_inference_nullSafety_mixed_outOfOrder() async {
9417+
featureSet = enableNnbd;
9418+
addLibrarySource('/a.dart', r'''
9419+
// @dart = 2.8
9420+
class A<T> {}
9421+
mixin M<U> on A<U> {}
9422+
''');
9423+
var library = await checkLibrary(r'''
9424+
import 'a.dart';
9425+
9426+
class B extends A<int> with M {}
9427+
''');
9428+
checkElementText(
9429+
library,
9430+
r'''
9431+
import 'a.dart';
9432+
class B extends A<int> with M<int> {
9433+
synthetic B();
9434+
}
9435+
''',
9436+
annotateNullability: true);
9437+
}
9438+
93519439
test_mixin_method_namedAsConstraint() async {
93529440
var library = await checkLibrary(r'''
93539441
class A {}

0 commit comments

Comments
 (0)