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

Commit 13deada

Browse files
author
Dart CI
committed
Version 2.11.0-173.0.dev
Merge commit '4129636e6c57db8b71e882982a0158c7dacd908c' into 'dev'
2 parents e2a4eab + 4129636 commit 13deada

14 files changed

+3548
-6
lines changed

pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,15 +1382,23 @@ class InferenceVisitor
13821382
spreadType, spreadTypeBound, element.isNullAware);
13831383
if (typeChecksNeeded) {
13841384
if (spreadElementType == null) {
1385-
if (inferrer.coreTypes
1386-
.isNull(inferrer.resolveTypeParameter(spreadType)) &&
1385+
if (inferrer.coreTypes.isNull(spreadTypeBound) &&
13871386
!element.isNullAware) {
13881387
replacement = inferrer.helper.buildProblem(
13891388
templateNonNullAwareSpreadIsNull.withArguments(
13901389
spreadType, inferrer.isNonNullableByDefault),
13911390
element.expression.fileOffset,
13921391
1);
13931392
} else {
1393+
if (inferrer.isNonNullableByDefault &&
1394+
spreadType.isPotentiallyNullable &&
1395+
spreadType is! DynamicType &&
1396+
spreadType != inferrer.coreTypes.nullType &&
1397+
!element.isNullAware) {
1398+
replacement = inferrer.helper.buildProblem(
1399+
messageNullableSpreadError, element.expression.fileOffset, 1);
1400+
}
1401+
13941402
replacement = inferrer.helper.buildProblem(
13951403
templateSpreadTypeMismatch.withArguments(
13961404
spreadType, inferrer.isNonNullableByDefault),
@@ -1406,7 +1414,8 @@ class InferenceVisitor
14061414
inferrer.isNonNullableByDefault),
14071415
element.expression.fileOffset,
14081416
1);
1409-
} else if (inferrer.isNonNullableByDefault &&
1417+
}
1418+
if (inferrer.isNonNullableByDefault &&
14101419
spreadType.isPotentiallyNullable &&
14111420
spreadType is! DynamicType &&
14121421
spreadType != inferrer.coreTypes.nullType &&
@@ -1815,8 +1824,7 @@ class InferenceVisitor
18151824
MapEntry replacement = entry;
18161825
if (typeChecksNeeded) {
18171826
if (actualKeyType == null) {
1818-
if (inferrer.coreTypes
1819-
.isNull(inferrer.resolveTypeParameter(spreadType)) &&
1827+
if (inferrer.coreTypes.isNull(spreadTypeBound) &&
18201828
!entry.isNullAware) {
18211829
replacement = new MapEntry(
18221830
inferrer.helper.buildProblem(
@@ -1827,6 +1835,18 @@ class InferenceVisitor
18271835
new NullLiteral())
18281836
..fileOffset = entry.fileOffset;
18291837
} else if (actualElementType != null) {
1838+
if (inferrer.isNonNullableByDefault &&
1839+
spreadType.isPotentiallyNullable &&
1840+
spreadType is! DynamicType &&
1841+
spreadType != inferrer.coreTypes.nullType &&
1842+
!entry.isNullAware) {
1843+
replacement = new SpreadMapEntry(
1844+
inferrer.helper.buildProblem(messageNullableSpreadError,
1845+
entry.expression.fileOffset, 1),
1846+
false)
1847+
..fileOffset = entry.fileOffset;
1848+
}
1849+
18301850
// Don't report the error here, it might be an ambiguous Set. The
18311851
// error is reported in checkMapEntry if it's disambiguated as map.
18321852
iterableSpreadType = spreadType;

pkg/front_end/testcases/nnbd/issue43256.dart.strong.expect

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ library /*isNonNullableByDefault*/;
2222
// if (i > 0) ...y, // error
2323
// ^
2424
//
25+
// pkg/front_end/testcases/nnbd/issue43256.dart:48:19: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced.
26+
// if (i > 0) ...x, // error
27+
// ^
28+
//
2529
// pkg/front_end/testcases/nnbd/issue43256.dart:48:19: Error: Unexpected type 'X' of a spread. Expected 'dynamic' or an Iterable.
2630
// if (i > 0) ...x, // error
2731
// ^
@@ -30,6 +34,10 @@ library /*isNonNullableByDefault*/;
3034
// if (i > 0) ...y, // error
3135
// ^
3236
//
37+
// pkg/front_end/testcases/nnbd/issue43256.dart:53:19: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced.
38+
// if (i > 0) ...x, // error
39+
// ^
40+
//
3341
// pkg/front_end/testcases/nnbd/issue43256.dart:53:19: Error: Unexpected type 'X' of a spread. Expected 'dynamic' or an Iterable.
3442
// if (i > 0) ...x, // error
3543
// ^

pkg/front_end/testcases/nnbd/issue43256.dart.strong.transformed.expect

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ library /*isNonNullableByDefault*/;
2222
// if (i > 0) ...y, // error
2323
// ^
2424
//
25+
// pkg/front_end/testcases/nnbd/issue43256.dart:48:19: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced.
26+
// if (i > 0) ...x, // error
27+
// ^
28+
//
2529
// pkg/front_end/testcases/nnbd/issue43256.dart:48:19: Error: Unexpected type 'X' of a spread. Expected 'dynamic' or an Iterable.
2630
// if (i > 0) ...x, // error
2731
// ^
@@ -30,6 +34,10 @@ library /*isNonNullableByDefault*/;
3034
// if (i > 0) ...y, // error
3135
// ^
3236
//
37+
// pkg/front_end/testcases/nnbd/issue43256.dart:53:19: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced.
38+
// if (i > 0) ...x, // error
39+
// ^
40+
//
3341
// pkg/front_end/testcases/nnbd/issue43256.dart:53:19: Error: Unexpected type 'X' of a spread. Expected 'dynamic' or an Iterable.
3442
// if (i > 0) ...x, // error
3543
// ^

pkg/front_end/testcases/nnbd/issue43256.dart.weak.expect

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ library /*isNonNullableByDefault*/;
2222
// if (i > 0) ...y, // error
2323
// ^
2424
//
25+
// pkg/front_end/testcases/nnbd/issue43256.dart:48:19: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced.
26+
// if (i > 0) ...x, // error
27+
// ^
28+
//
2529
// pkg/front_end/testcases/nnbd/issue43256.dart:48:19: Error: Unexpected type 'X' of a spread. Expected 'dynamic' or an Iterable.
2630
// if (i > 0) ...x, // error
2731
// ^
@@ -30,6 +34,10 @@ library /*isNonNullableByDefault*/;
3034
// if (i > 0) ...y, // error
3135
// ^
3236
//
37+
// pkg/front_end/testcases/nnbd/issue43256.dart:53:19: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced.
38+
// if (i > 0) ...x, // error
39+
// ^
40+
//
3341
// pkg/front_end/testcases/nnbd/issue43256.dart:53:19: Error: Unexpected type 'X' of a spread. Expected 'dynamic' or an Iterable.
3442
// if (i > 0) ...x, // error
3543
// ^

pkg/front_end/testcases/nnbd/issue43256.dart.weak.transformed.expect

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ library /*isNonNullableByDefault*/;
2222
// if (i > 0) ...y, // error
2323
// ^
2424
//
25+
// pkg/front_end/testcases/nnbd/issue43256.dart:48:19: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced.
26+
// if (i > 0) ...x, // error
27+
// ^
28+
//
2529
// pkg/front_end/testcases/nnbd/issue43256.dart:48:19: Error: Unexpected type 'X' of a spread. Expected 'dynamic' or an Iterable.
2630
// if (i > 0) ...x, // error
2731
// ^
@@ -30,6 +34,10 @@ library /*isNonNullableByDefault*/;
3034
// if (i > 0) ...y, // error
3135
// ^
3236
//
37+
// pkg/front_end/testcases/nnbd/issue43256.dart:53:19: Error: An expression whose value can be 'null' must be null-checked before it can be dereferenced.
38+
// if (i > 0) ...x, // error
39+
// ^
40+
//
3341
// pkg/front_end/testcases/nnbd/issue43256.dart:53:19: Error: Unexpected type 'X' of a spread. Expected 'dynamic' or an Iterable.
3442
// if (i > 0) ...x, // error
3543
// ^
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
foo(bool condition, Iterable<dynamic> iterable, List<int>? a, Set<int>? b,
6+
Iterable<int>? c, Map<int, int>? d) {
7+
return [
8+
{...a}, // Error.
9+
{...b}, // Error.
10+
{...c}, // Error.
11+
{...d}, // Error.
12+
<int, int>{...a}, // Error.
13+
<int>{...d}, // Error.
14+
{if (condition) ...a}, // Error.
15+
{if (condition) ...b}, // Error.
16+
{if (condition) ...c}, // Error.
17+
{if (condition) ...d}, // Error.
18+
{for (dynamic e in iterable) ...a}, // Error.
19+
{for (dynamic e in iterable) ...b}, // Error.
20+
{for (dynamic e in iterable) ...c}, // Error.
21+
{for (dynamic e in iterable) ...d}, // Error.
22+
{for (int i = 0; i < 42; ++i) ...a}, // Error.
23+
{for (int i = 0; i < 42; ++i) ...b}, // Error.
24+
{for (int i = 0; i < 42; ++i) ...c}, // Error.
25+
{for (int i = 0; i < 42; ++i) ...d}, // Error.
26+
27+
{...?a}, // Ok.
28+
{...?b}, // Ok.
29+
{...?c}, // Ok.
30+
{...?d}, // Ok.
31+
{if (condition) ...?a}, // Ok.
32+
{if (condition) ...?b}, // Ok.
33+
{if (condition) ...?c}, // Ok.
34+
{if (condition) ...?d}, // Ok.
35+
{for (dynamic e in iterable) ...?a}, // Ok.
36+
{for (dynamic e in iterable) ...?b}, // Ok.
37+
{for (dynamic e in iterable) ...?c}, // Ok.
38+
{for (dynamic e in iterable) ...?d}, // Ok.
39+
{for (int i = 0; i < 42; ++i) ...?a}, // Ok.
40+
{for (int i = 0; i < 42; ++i) ...?b}, // Ok.
41+
{for (int i = 0; i < 42; ++i) ...?c}, // Ok.
42+
{for (int i = 0; i < 42; ++i) ...?d}, // Ok.
43+
];
44+
}
45+
46+
bar<X extends List<int>?, Y extends Set<int>?, Z extends Iterable<int>?,
47+
W extends Map<int, int>?>(
48+
bool condition, Iterable<dynamic> iterable, X x, Y y, Z z, W w) {
49+
return [
50+
{...x}, // Error.
51+
{...y}, // Error.
52+
{...z}, // Error.
53+
{...w}, // Error.
54+
<int, int>{...x}, // Error.
55+
<int>{...w}, // Error.
56+
{if (condition) ...x}, // Error.
57+
{if (condition) ...y}, // Error.
58+
{if (condition) ...z}, // Error.
59+
{if (condition) ...w}, // Error.
60+
{for (dynamic e in iterable) ...x}, // Error.
61+
{for (dynamic e in iterable) ...y}, // Error.
62+
{for (dynamic e in iterable) ...z}, // Error.
63+
{for (dynamic e in iterable) ...w}, // Error.
64+
{for (int i = 0; i < 42; ++i) ...x}, // Error.
65+
{for (int i = 0; i < 42; ++i) ...y}, // Error.
66+
{for (int i = 0; i < 42; ++i) ...z}, // Error.
67+
{for (int i = 0; i < 42; ++i) ...w}, // Error.
68+
69+
{...?x}, // Ok.
70+
{...?y}, // Ok.
71+
{...?z}, // Ok.
72+
{...?w}, // Ok.
73+
{if (condition) ...?x}, // Ok.
74+
{if (condition) ...?y}, // Ok.
75+
{if (condition) ...?z}, // Ok.
76+
{if (condition) ...?w}, // Ok.
77+
{for (dynamic e in iterable) ...?x}, // Ok.
78+
{for (dynamic e in iterable) ...?y}, // Ok.
79+
{for (dynamic e in iterable) ...?z}, // Ok.
80+
{for (dynamic e in iterable) ...?w}, // Ok.
81+
{for (int i = 0; i < 42; ++i) ...?x}, // Ok.
82+
{for (int i = 0; i < 42; ++i) ...?y}, // Ok.
83+
{for (int i = 0; i < 42; ++i) ...?z}, // Ok.
84+
{for (int i = 0; i < 42; ++i) ...?w}, // Ok.
85+
];
86+
}
87+
88+
main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method foo(core::bool condition, core::Iterable<dynamic> iterable, core::List<core::int>? a, core::Set<core::int>? b, core::Iterable<core::int>? c, core::Map<core::int, core::int>? d) → dynamic
6+
;
7+
static method bar<X extends core::List<core::int>? = core::List<core::int>?, Y extends core::Set<core::int>? = core::Set<core::int>?, Z extends core::Iterable<core::int>? = core::Iterable<core::int>?, W extends core::Map<core::int, core::int>? = core::Map<core::int, core::int>?>(core::bool condition, core::Iterable<dynamic> iterable, self::bar::X% x, self::bar::Y% y, self::bar::Z% z, self::bar::W% w) → dynamic
8+
;
9+
static method main() → dynamic
10+
;

0 commit comments

Comments
 (0)