Skip to content

Commit

Permalink
Issue 42605. Do LEGACY_ERASURE when checking inferred mixin type argu…
Browse files Browse the repository at this point in the history
…ments.

Bug: #42605
Change-Id: I58d27352e770ce63fabc0da2c07920dbadb8af11
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153482
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
scheglov committed Jul 8, 2020
1 parent ec30a30 commit eada9fa
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ typedef WorkToWaitAfterComputingResult = Future<void> Function(String path);
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
class AnalysisDriver implements AnalysisDriverGeneric {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 104;
static const int DATA_VERSION = 105;

/// The length of the list returned by [_computeDeclaredVariablesSignature].
static const int _declaredVariablesSignatureLength = 4;
Expand Down
21 changes: 15 additions & 6 deletions pkg/analyzer/lib/src/dart/element/type_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,16 @@ abstract class TypeSystem implements public.TypeSystem {
var substitution = Substitution.fromPairs(typeParameters, inferredTypes);

for (int i = 0; i < srcTypes.length; i++) {
if (substitution.substituteType(srcTypes[i]) != destTypes[i]) {
var srcType = substitution.substituteType(srcTypes[i]);
var destType = destTypes[i];
if (isNonNullableByDefault) {
// TODO(scheglov) waiting for the spec
// https://github.com/dart-lang/sdk/issues/42605
} else {
srcType = toLegacyType(srcType);
destType = toLegacyType(destType);
}
if (srcType != destType) {
// Failed to find an appropriate substitution
return null;
}
Expand Down Expand Up @@ -345,6 +354,11 @@ abstract class TypeSystem implements public.TypeSystem {
return type;
}

DartType toLegacyType(DartType type) {
if (isNonNullableByDefault) return type;
return NullabilityEliminator.perform(typeProvider, type);
}

/// Tries to promote from the first type from the second type, and returns the
/// promoted type if it succeeds, otherwise null.
DartType tryPromoteToType(DartType to, DartType from);
Expand Down Expand Up @@ -1427,11 +1441,6 @@ class TypeSystemImpl extends TypeSystem {
return RuntimeTypeEqualityHelper(this).equal(T1, T2);
}

DartType toLegacyType(DartType type) {
if (isNonNullableByDefault) return type;
return NullabilityEliminator.perform(typeProvider, type);
}

/// Merges two types into a single type.
/// Compute the canonical representation of [T].
///
Expand Down
11 changes: 8 additions & 3 deletions pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/null_safety_understanding_flag.dart';
import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/dart/analysis/session.dart';
import 'package:analyzer/src/dart/element/class_hierarchy.dart';
Expand Down Expand Up @@ -108,9 +109,13 @@ class ResynthesizeAst2Test extends ResynthesizeTestStrategyTwoPhase
LinkedBundleContext(elementFactory, sdkBundle),
);

var linkResult = link(
elementFactory,
inputLibraries,
var linkResult = NullSafetyUnderstandingFlag.enableNullSafetyTypes(
() {
return link(
elementFactory,
inputLibraries,
);
},
);

elementFactory.addBundle(
Expand Down
88 changes: 88 additions & 0 deletions pkg/analyzer/test/src/summary/resynthesize_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'element_text.dart';
import 'test_strategies.dart';
Expand Down Expand Up @@ -9348,6 +9349,93 @@ mixin M on Object {
''');
}

test_mixin_inference_legacy() async {
var library = await checkLibrary(r'''
class A<T> {}
mixin M<U> on A<U> {}
class B extends A<int> with M {}
''');
checkElementText(
library,
r'''
class A<T> {
}
class B extends A<int*>* with M<int*>* {
synthetic B();
}
mixin M<U> on A<U*>* {
}
''',
annotateNullability: true);
}

test_mixin_inference_nullSafety() async {
featureSet = enableNnbd;
var library = await checkLibrary(r'''
class A<T> {}
mixin M<U> on A<U> {}
class B extends A<int> with M {}
''');
checkElementText(
library,
r'''
class A<T> {
}
class B extends A<int> with M<int> {
synthetic B();
}
mixin M<U> on A<U> {
}
''',
annotateNullability: true);
}

test_mixin_inference_nullSafety_mixed_inOrder() async {
featureSet = enableNnbd;
addLibrarySource('/a.dart', r'''
class A<T> {}
mixin M<U> on A<U> {}
''');
var library = await checkLibrary(r'''
// @dart = 2.8
import 'a.dart';
class B extends A<int> with M {}
''');
checkElementText(
library,
r'''
import 'a.dart';
class B extends A<int*>* with M<int*>* {
synthetic B();
}
''',
annotateNullability: true);
}

@FailingTest(reason: 'Out-of-order inference is not specified yet')
test_mixin_inference_nullSafety_mixed_outOfOrder() async {
featureSet = enableNnbd;
addLibrarySource('/a.dart', r'''
// @dart = 2.8
class A<T> {}
mixin M<U> on A<U> {}
''');
var library = await checkLibrary(r'''
import 'a.dart';
class B extends A<int> with M {}
''');
checkElementText(
library,
r'''
import 'a.dart';
class B extends A<int> with M<int> {
synthetic B();
}
''',
annotateNullability: true);
}

test_mixin_method_namedAsConstraint() async {
var library = await checkLibrary(r'''
class A {}
Expand Down

0 comments on commit eada9fa

Please sign in to comment.