Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit aac5126

Browse files
author
Dart CI
committed
Version 2.11.0-159.0.dev
Merge commit 'd3114bac63b8ec22e8dfee4bb91b3f4c8c1fab59' into 'dev'
2 parents 6400f73 + d3114ba commit aac5126

18 files changed

+391
-118
lines changed

pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart

Lines changed: 12 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import 'package:kernel/core_types.dart';
88

99
import 'package:kernel/type_algebra.dart';
1010

11-
import 'package:kernel/src/replacement_visitor.dart';
12-
1311
import 'package:kernel/type_environment.dart';
1412

1513
import 'type_schema.dart' show UnknownType;
@@ -877,12 +875,18 @@ abstract class TypeConstraintGatherer {
877875
List<_ProtoConstraint> constraints =
878876
_protoConstraints.sublist(baseConstraintCount);
879877
_protoConstraints.length = baseConstraintCount;
880-
_NullabilityAwareTypeVariableEliminator eliminator =
881-
new _NullabilityAwareTypeVariableEliminator(
882-
freshTypeParameters.freshTypeParameters.toSet(),
883-
const NeverType(Nullability.nonNullable),
884-
coreTypes.objectNullableRawType,
885-
coreTypes.functionNonNullableRawType);
878+
NullabilityAwareTypeVariableEliminator eliminator =
879+
new NullabilityAwareTypeVariableEliminator(
880+
eliminationTargets:
881+
freshTypeParameters.freshTypeParameters.toSet(),
882+
bottomType: const NeverType(Nullability.nonNullable),
883+
topType: coreTypes.objectNullableRawType,
884+
topFunctionType: coreTypes.functionNonNullableRawType,
885+
unhandledTypeHandler: (DartType type, ignored) =>
886+
type is UnknownType
887+
? false
888+
: throw new UnsupportedError(
889+
"Unsupported type '${type.runtimeType}'."));
886890
for (_ProtoConstraint constraint in constraints) {
887891
if (constraint.isUpper) {
888892
_constrainParameterUpper(constraint.parameter,
@@ -1177,85 +1181,3 @@ class _ProtoConstraint {
11771181
: "$bound <: ${parameter.name}";
11781182
}
11791183
}
1180-
1181-
/// Eliminates specified free type parameters in a type.
1182-
///
1183-
/// The algorithm for elimination of type variables is described in
1184-
/// https://github.com/dart-lang/language/pull/957
1185-
class _NullabilityAwareTypeVariableEliminator extends ReplacementVisitor {
1186-
final DartType bottomType;
1187-
final DartType topType;
1188-
final DartType topFunctionType;
1189-
final Set<TypeParameter> eliminationTargets;
1190-
bool isLeastClosure;
1191-
bool isCovariant = true;
1192-
1193-
_NullabilityAwareTypeVariableEliminator(this.eliminationTargets,
1194-
this.bottomType, this.topType, this.topFunctionType);
1195-
1196-
/// Returns a subtype of [type] for all values of [eliminationTargets].
1197-
DartType eliminateToLeast(DartType type) {
1198-
isCovariant = true;
1199-
isLeastClosure = true;
1200-
return type.accept(this) ?? type;
1201-
}
1202-
1203-
/// Returns a supertype of [type] for all values of [eliminationTargets].
1204-
DartType eliminateToGreatest(DartType type) {
1205-
isCovariant = true;
1206-
isLeastClosure = false;
1207-
return type.accept(this) ?? type;
1208-
}
1209-
1210-
DartType get typeParameterReplacement {
1211-
return isLeastClosure && isCovariant || (!isLeastClosure && !isCovariant)
1212-
? bottomType
1213-
: topType;
1214-
}
1215-
1216-
DartType get functionReplacement {
1217-
return isLeastClosure && isCovariant || (!isLeastClosure && !isCovariant)
1218-
? bottomType
1219-
: topFunctionType;
1220-
}
1221-
1222-
@override
1223-
void changeVariance() {
1224-
isCovariant = !isCovariant;
1225-
}
1226-
1227-
@override
1228-
DartType visitFunctionType(FunctionType node) {
1229-
// - if `S` is
1230-
// `T Function<X0 extends B0, ...., Xk extends Bk>(T0 x0, ...., Tn xn,
1231-
// [Tn+1 xn+1, ..., Tm xm])`
1232-
// or `T Function<X0 extends B0, ...., Xk extends Bk>(T0 x0, ...., Tn xn,
1233-
// {Tn+1 xn+1, ..., Tm xm})`
1234-
// and `L` contains any free type variables from any of the `Bi`:
1235-
// - The least closure of `S` with respect to `L` is `Never`
1236-
// - The greatest closure of `S` with respect to `L` is `Function`
1237-
if (node.typeParameters.isNotEmpty) {
1238-
for (TypeParameter typeParameter in node.typeParameters) {
1239-
if (containsTypeVariable(typeParameter.bound, eliminationTargets,
1240-
unhandledTypeHandler: (DartType type, ignored) =>
1241-
type is UnknownType
1242-
? false
1243-
: throw new UnsupportedError(
1244-
"Unsupported type '${type.runtimeType}'."))) {
1245-
return functionReplacement;
1246-
}
1247-
}
1248-
}
1249-
return super.visitFunctionType(node);
1250-
}
1251-
1252-
@override
1253-
DartType visitTypeParameterType(TypeParameterType node) {
1254-
if (eliminationTargets.contains(node.parameter)) {
1255-
return typeParameterReplacement.withDeclaredNullability(
1256-
uniteNullabilities(
1257-
typeParameterReplacement.nullability, node.nullability));
1258-
}
1259-
return super.visitTypeParameterType(node);
1260-
}
1261-
}

pkg/front_end/test/fasta/type_inference/type_schema_environment_nnbd_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ class TypeSchemaEnvironmentTest {
661661
null,
662662
inferredTypes,
663663
testLib);
664-
expect(inferredTypes[0], coreTypes.numNonNullableRawType);
664+
expect(inferredTypes[0], coreTypes.numLegacyRawType);
665665
}
666666
}
667667

@@ -1066,13 +1066,13 @@ class TypeSchemaEnvironmentTest {
10661066

10671067
// TODO(dmitryas): Test for various nullabilities.
10681068
testUpper("T", "T", "T", typeParameters: "T extends Object");
1069-
testUpper("T", "List<Never>", "List<Object>",
1069+
testUpper("T", "List<Never>", "List<Object?>",
10701070
typeParameters: "T extends List<T>");
1071-
testUpper("List<Never>", "T", "List<Object>",
1071+
testUpper("List<Never>", "T", "List<Object?>",
10721072
typeParameters: "T extends List<T>");
1073-
testUpper("T", "U", "List<Object>",
1073+
testUpper("T", "U", "List<Object?>",
10741074
typeParameters: "T extends List<T>, U extends List<Never>");
1075-
testUpper("U", "T", "List<Object>",
1075+
testUpper("U", "T", "List<Object?>",
10761076
typeParameters: "T extends List<T>, U extends List<Never>");
10771077
}
10781078

pkg/front_end/test/spell_checking_list_code.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ b
7373
b0i
7474
b0m
7575
b0n
76+
b1a
7677
b1i
7778
b1m
7879
b1n
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
assertRightSubtype(dynamic x) {
6+
x as Set<Object?>;
7+
}
8+
9+
assertLeftSubtype<X>(X x) {
10+
new Set<Object?>() as X;
11+
}
12+
13+
class C<X extends Object?, Y extends Object> {
14+
test(X x, Y? y) {
15+
var v = {x, 42}; // Checking UP(X, int).
16+
var w = {42, x}; // Checking UP(int, X).
17+
var p = {y, 42}; // Checking UP(Y?, int).
18+
var q = {42, y}; // Checking UP(int, Y?).
19+
20+
// Check that variable types are both subtype and supertype of Set<Object?>.
21+
assertRightSubtype(v);
22+
assertLeftSubtype(v);
23+
assertRightSubtype(w);
24+
assertLeftSubtype(w);
25+
assertRightSubtype(p);
26+
assertLeftSubtype(p);
27+
assertRightSubtype(q);
28+
assertLeftSubtype(q);
29+
30+
// Check the same for intersection types.
31+
if (x is Object?) {
32+
var v = {x, 42}; // Checking UP(X & Object?, int).
33+
var w = {42, x}; // Checking UP(int, X & Object?).
34+
35+
assertRightSubtype(v);
36+
assertLeftSubtype(v);
37+
assertRightSubtype(w);
38+
assertLeftSubtype(w);
39+
}
40+
}
41+
}
42+
43+
main() {
44+
new C<int?, int>().test(42, null);
45+
new C<int?, int>().test(null, null);
46+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class C<X extends core::Object? = core::Object?, Y extends core::Object = core::Object> extends core::Object {
6+
synthetic constructor •() → self::C<self::C::X%, self::C::Y>
7+
;
8+
method test(generic-covariant-impl self::C::X% x, generic-covariant-impl self::C::Y? y) → dynamic
9+
;
10+
}
11+
static method assertRightSubtype(dynamic x) → dynamic
12+
;
13+
static method assertLeftSubtype<X extends core::Object? = dynamic>(self::assertLeftSubtype::X% x) → dynamic
14+
;
15+
static method main() → dynamic
16+
;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:collection" as col;
5+
6+
class C<X extends core::Object? = core::Object?, Y extends core::Object = core::Object> extends core::Object {
7+
synthetic constructor •() → self::C<self::C::X%, self::C::Y>
8+
: super core::Object::•()
9+
;
10+
method test(generic-covariant-impl self::C::X% x, generic-covariant-impl self::C::Y? y) → dynamic {
11+
core::Set<core::Object?> v = let final core::Set<core::Object?> #t1 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t2 = #t1.{core::Set::add}(x) in let final dynamic #t3 = #t1.{core::Set::add}(42) in #t1;
12+
core::Set<core::Object?> w = let final core::Set<core::Object?> #t4 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t5 = #t4.{core::Set::add}(42) in let final dynamic #t6 = #t4.{core::Set::add}(x) in #t4;
13+
core::Set<core::Object?> p = let final core::Set<core::Object?> #t7 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t8 = #t7.{core::Set::add}(y) in let final dynamic #t9 = #t7.{core::Set::add}(42) in #t7;
14+
core::Set<core::Object?> q = let final core::Set<core::Object?> #t10 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t11 = #t10.{core::Set::add}(42) in let final dynamic #t12 = #t10.{core::Set::add}(y) in #t10;
15+
self::assertRightSubtype(v);
16+
self::assertLeftSubtype<core::Set<core::Object?>>(v);
17+
self::assertRightSubtype(w);
18+
self::assertLeftSubtype<core::Set<core::Object?>>(w);
19+
self::assertRightSubtype(p);
20+
self::assertLeftSubtype<core::Set<core::Object?>>(p);
21+
self::assertRightSubtype(q);
22+
self::assertLeftSubtype<core::Set<core::Object?>>(q);
23+
if(x is{ForNonNullableByDefault} core::Object?) {
24+
core::Set<core::Object?> v = let final core::Set<core::Object?> #t13 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t14 = #t13.{core::Set::add}(x{self::C::X% & core::Object? /* '%' & '?' = '%' */}) in let final dynamic #t15 = #t13.{core::Set::add}(42) in #t13;
25+
core::Set<core::Object?> w = let final core::Set<core::Object?> #t16 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t17 = #t16.{core::Set::add}(42) in let final dynamic #t18 = #t16.{core::Set::add}(x{self::C::X% & core::Object? /* '%' & '?' = '%' */}) in #t16;
26+
self::assertRightSubtype(v);
27+
self::assertLeftSubtype<core::Set<core::Object?>>(v);
28+
self::assertRightSubtype(w);
29+
self::assertLeftSubtype<core::Set<core::Object?>>(w);
30+
}
31+
}
32+
}
33+
static method assertRightSubtype(dynamic x) → dynamic {
34+
x as{ForNonNullableByDefault} core::Set<core::Object?>;
35+
}
36+
static method assertLeftSubtype<X extends core::Object? = dynamic>(self::assertLeftSubtype::X% x) → dynamic {
37+
col::LinkedHashSet::•<core::Object?>() as{ForNonNullableByDefault} self::assertLeftSubtype::X%;
38+
}
39+
static method main() → dynamic {
40+
new self::C::•<core::int?, core::int>().{self::C::test}(42, null);
41+
new self::C::•<core::int?, core::int>().{self::C::test}(null, null);
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:collection" as col;
5+
6+
class C<X extends core::Object? = core::Object?, Y extends core::Object = core::Object> extends core::Object {
7+
synthetic constructor •() → self::C<self::C::X%, self::C::Y>
8+
: super core::Object::•()
9+
;
10+
method test(generic-covariant-impl self::C::X% x, generic-covariant-impl self::C::Y? y) → dynamic {
11+
core::Set<core::Object?> v = let final core::Set<core::Object?> #t1 = new col::_CompactLinkedHashSet::•<core::Object?>() in let final core::bool #t2 = #t1.{core::Set::add}(x) in let final core::bool #t3 = #t1.{core::Set::add}(42) in #t1;
12+
core::Set<core::Object?> w = let final core::Set<core::Object?> #t4 = new col::_CompactLinkedHashSet::•<core::Object?>() in let final core::bool #t5 = #t4.{core::Set::add}(42) in let final core::bool #t6 = #t4.{core::Set::add}(x) in #t4;
13+
core::Set<core::Object?> p = let final core::Set<core::Object?> #t7 = new col::_CompactLinkedHashSet::•<core::Object?>() in let final core::bool #t8 = #t7.{core::Set::add}(y) in let final core::bool #t9 = #t7.{core::Set::add}(42) in #t7;
14+
core::Set<core::Object?> q = let final core::Set<core::Object?> #t10 = new col::_CompactLinkedHashSet::•<core::Object?>() in let final core::bool #t11 = #t10.{core::Set::add}(42) in let final core::bool #t12 = #t10.{core::Set::add}(y) in #t10;
15+
self::assertRightSubtype(v);
16+
self::assertLeftSubtype<core::Set<core::Object?>>(v);
17+
self::assertRightSubtype(w);
18+
self::assertLeftSubtype<core::Set<core::Object?>>(w);
19+
self::assertRightSubtype(p);
20+
self::assertLeftSubtype<core::Set<core::Object?>>(p);
21+
self::assertRightSubtype(q);
22+
self::assertLeftSubtype<core::Set<core::Object?>>(q);
23+
if(x is{ForNonNullableByDefault} core::Object?) {
24+
core::Set<core::Object?> v = let final core::Set<core::Object?> #t13 = new col::_CompactLinkedHashSet::•<core::Object?>() in let final core::bool #t14 = #t13.{core::Set::add}(x{self::C::X% & core::Object? /* '%' & '?' = '%' */}) in let final core::bool #t15 = #t13.{core::Set::add}(42) in #t13;
25+
core::Set<core::Object?> w = let final core::Set<core::Object?> #t16 = new col::_CompactLinkedHashSet::•<core::Object?>() in let final core::bool #t17 = #t16.{core::Set::add}(42) in let final core::bool #t18 = #t16.{core::Set::add}(x{self::C::X% & core::Object? /* '%' & '?' = '%' */}) in #t16;
26+
self::assertRightSubtype(v);
27+
self::assertLeftSubtype<core::Set<core::Object?>>(v);
28+
self::assertRightSubtype(w);
29+
self::assertLeftSubtype<core::Set<core::Object?>>(w);
30+
}
31+
}
32+
}
33+
static method assertRightSubtype(dynamic x) → dynamic {
34+
x as{ForNonNullableByDefault} core::Set<core::Object?>;
35+
}
36+
static method assertLeftSubtype<X extends core::Object? = dynamic>(self::assertLeftSubtype::X% x) → dynamic {
37+
new col::_CompactLinkedHashSet::•<core::Object?>() as{ForNonNullableByDefault} self::assertLeftSubtype::X%;
38+
}
39+
static method main() → dynamic {
40+
new self::C::•<core::int?, core::int>().{self::C::test}(42, null);
41+
new self::C::•<core::int?, core::int>().{self::C::test}(null, null);
42+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
assertRightSubtype(dynamic x) {}
2+
assertLeftSubtype<X>(X x) {}
3+
4+
class C<X extends Object?, Y extends Object> {
5+
test(X x, Y? y) {}
6+
}
7+
8+
main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
assertLeftSubtype<X>(X x) {}
2+
assertRightSubtype(dynamic x) {}
3+
4+
class C<X extends Object?, Y extends Object> {
5+
test(X x, Y? y) {}
6+
}
7+
8+
main() {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:collection" as col;
5+
6+
class C<X extends core::Object? = core::Object?, Y extends core::Object = core::Object> extends core::Object {
7+
synthetic constructor •() → self::C<self::C::X%, self::C::Y>
8+
: super core::Object::•()
9+
;
10+
method test(generic-covariant-impl self::C::X% x, generic-covariant-impl self::C::Y? y) → dynamic {
11+
core::Set<core::Object?> v = let final core::Set<core::Object?> #t1 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t2 = #t1.{core::Set::add}(x) in let final dynamic #t3 = #t1.{core::Set::add}(42) in #t1;
12+
core::Set<core::Object?> w = let final core::Set<core::Object?> #t4 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t5 = #t4.{core::Set::add}(42) in let final dynamic #t6 = #t4.{core::Set::add}(x) in #t4;
13+
core::Set<core::Object?> p = let final core::Set<core::Object?> #t7 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t8 = #t7.{core::Set::add}(y) in let final dynamic #t9 = #t7.{core::Set::add}(42) in #t7;
14+
core::Set<core::Object?> q = let final core::Set<core::Object?> #t10 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t11 = #t10.{core::Set::add}(42) in let final dynamic #t12 = #t10.{core::Set::add}(y) in #t10;
15+
self::assertRightSubtype(v);
16+
self::assertLeftSubtype<core::Set<core::Object?>>(v);
17+
self::assertRightSubtype(w);
18+
self::assertLeftSubtype<core::Set<core::Object?>>(w);
19+
self::assertRightSubtype(p);
20+
self::assertLeftSubtype<core::Set<core::Object?>>(p);
21+
self::assertRightSubtype(q);
22+
self::assertLeftSubtype<core::Set<core::Object?>>(q);
23+
if(x is{ForNonNullableByDefault} core::Object?) {
24+
core::Set<core::Object?> v = let final core::Set<core::Object?> #t13 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t14 = #t13.{core::Set::add}(x{self::C::X% & core::Object? /* '%' & '?' = '%' */}) in let final dynamic #t15 = #t13.{core::Set::add}(42) in #t13;
25+
core::Set<core::Object?> w = let final core::Set<core::Object?> #t16 = col::LinkedHashSet::•<core::Object?>() in let final dynamic #t17 = #t16.{core::Set::add}(42) in let final dynamic #t18 = #t16.{core::Set::add}(x{self::C::X% & core::Object? /* '%' & '?' = '%' */}) in #t16;
26+
self::assertRightSubtype(v);
27+
self::assertLeftSubtype<core::Set<core::Object?>>(v);
28+
self::assertRightSubtype(w);
29+
self::assertLeftSubtype<core::Set<core::Object?>>(w);
30+
}
31+
}
32+
}
33+
static method assertRightSubtype(dynamic x) → dynamic {
34+
x as{ForNonNullableByDefault} core::Set<core::Object?>;
35+
}
36+
static method assertLeftSubtype<X extends core::Object? = dynamic>(self::assertLeftSubtype::X% x) → dynamic {
37+
col::LinkedHashSet::•<core::Object?>() as{ForNonNullableByDefault} self::assertLeftSubtype::X%;
38+
}
39+
static method main() → dynamic {
40+
new self::C::•<core::int?, core::int>().{self::C::test}(42, null);
41+
new self::C::•<core::int?, core::int>().{self::C::test}(null, null);
42+
}

0 commit comments

Comments
 (0)