Skip to content

Commit 8d8c4c6

Browse files
johnniwintherCommit Queue
authored and
Commit Queue
committed
[cfe] Handle extension types in *Concatenation nodes
Closes #54357 Change-Id: Ie5ff5c6c61c537658dcc6715054ff82c6f8537c4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341961 Reviewed-by: Jens Johansen <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent f49c786 commit 8d8c4c6

11 files changed

+453
-3
lines changed

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,8 +3089,15 @@ class ConstantEvaluator implements ExpressionVisitor<Constant> {
30893089

30903090
@override
30913091
Constant visitListConcatenation(ListConcatenation node) {
3092+
DartType? type = _evaluateDartType(node, node.typeArgument);
3093+
if (type == null) {
3094+
AbortConstant error = _gotError!;
3095+
_gotError = null;
3096+
return error;
3097+
}
3098+
assert(_gotError == null);
30923099
final ListConstantBuilder builder =
3093-
new ListConstantBuilder(node, convertType(node.typeArgument), this);
3100+
new ListConstantBuilder(node, convertType(type), this);
30943101
for (Expression list in node.lists) {
30953102
AbortConstant? error = builder.addSpread(list);
30963103
if (error != null) return error;
@@ -3134,8 +3141,15 @@ class ConstantEvaluator implements ExpressionVisitor<Constant> {
31343141

31353142
@override
31363143
Constant visitSetConcatenation(SetConcatenation node) {
3144+
DartType? type = _evaluateDartType(node, node.typeArgument);
3145+
if (type == null) {
3146+
AbortConstant error = _gotError!;
3147+
_gotError = null;
3148+
return error;
3149+
}
3150+
assert(_gotError == null);
31373151
final SetConstantBuilder builder =
3138-
new SetConstantBuilder(node, convertType(node.typeArgument), this);
3152+
new SetConstantBuilder(node, convertType(type), this);
31393153
for (Expression set_ in node.sets) {
31403154
AbortConstant? error = builder.addSpread(set_);
31413155
if (error != null) return error;
@@ -3187,8 +3201,22 @@ class ConstantEvaluator implements ExpressionVisitor<Constant> {
31873201

31883202
@override
31893203
Constant visitMapConcatenation(MapConcatenation node) {
3204+
DartType? keyType = _evaluateDartType(node, node.keyType);
3205+
if (keyType == null) {
3206+
AbortConstant error = _gotError!;
3207+
_gotError = null;
3208+
return error;
3209+
}
3210+
assert(_gotError == null);
3211+
DartType? valueType = _evaluateDartType(node, node.valueType);
3212+
if (valueType == null) {
3213+
AbortConstant error = _gotError!;
3214+
_gotError = null;
3215+
return error;
3216+
}
3217+
assert(_gotError == null);
31903218
final MapConstantBuilder builder = new MapConstantBuilder(
3191-
node, convertType(node.keyType), convertType(node.valueType), this);
3219+
node, convertType(keyType), convertType(valueType), this);
31923220
for (Expression map in node.maps) {
31933221
AbortConstant? error = builder.addSpread(map);
31943222
if (error != null) return error;

pkg/front_end/test/spell_checking_list_tests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ estat
285285
et
286286
everytime
287287
evicting
288+
ex
288289
examines
289290
exceed
290291
excess
@@ -705,6 +706,7 @@ splitting
705706
spurious
706707
sqrt
707708
squared
709+
ss
708710
sssp
709711
stacks
710712
stashed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2023, 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+
const ex3 = ExInt(3);
6+
const ex4 = ExInt(4);
7+
8+
const l3 = [ex3];
9+
const l4 = [ex4];
10+
const l34i = [ex3 as int, ... l4 as List<int>];
11+
const l43 = [ex4, ex3];
12+
const l3s4 = [ex3, ... l4];
13+
const ls43 = [... l4, ex3];
14+
const ls3s4 = [... l3, ... l4];
15+
16+
const s3 = {ex3};
17+
const s4 = {ex4};
18+
const s34i = {ex3 as int, ... s4 as Set<int>};
19+
const s43 = {ex4, ex3};
20+
const s3s4 = {ex3, ... s4};
21+
const ss43 = {... s4, ex3};
22+
const ss3s4 = {... s3, ... s4};
23+
24+
const m3 = {ex3: ex3};
25+
const m4 = {ex4: ex4};
26+
const m34i = {ex3 as int: ex3 as int, ... m4 as Map<int, int>};
27+
const m43 = {ex4: ex4, ex3: ex3};
28+
const m3s4 = {ex3: ex3, ... m4};
29+
const ms43 = {... m4, ex3: ex3};
30+
const ms3s4 = {... m3, ... m4};
31+
32+
extension type const ExInt(int _) implements int {}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
extension type ExInt(core::int _) implements core::int {
6+
abstract extension-type-member representation-field get _() → core::int;
7+
constructor • = self::ExInt|constructor#;
8+
constructor tearoff • = self::ExInt|constructor#_#new#tearOff;
9+
}
10+
static const field self::ExInt /* = core::int */ ex3 = #C1;
11+
static const field self::ExInt /* = core::int */ ex4 = #C2;
12+
static const field core::List<self::ExInt /* = core::int */> l3 = #C3;
13+
static const field core::List<self::ExInt /* = core::int */> l4 = #C4;
14+
static const field core::List<core::int> l34i = #C5;
15+
static const field core::List<self::ExInt /* = core::int */> l43 = #C6;
16+
static const field core::List<self::ExInt /* = core::int */> l3s4 = #C5;
17+
static const field core::List<self::ExInt /* = core::int */> ls43 = #C6;
18+
static const field core::List<self::ExInt /* = core::int */> ls3s4 = #C5;
19+
static const field core::Set<self::ExInt /* = core::int */> s3 = #C7;
20+
static const field core::Set<self::ExInt /* = core::int */> s4 = #C8;
21+
static const field core::Set<core::int> s34i = #C9;
22+
static const field core::Set<self::ExInt /* = core::int */> s43 = #C10;
23+
static const field core::Set<self::ExInt /* = core::int */> s3s4 = #C9;
24+
static const field core::Set<self::ExInt /* = core::int */> ss43 = #C10;
25+
static const field core::Set<self::ExInt /* = core::int */> ss3s4 = #C9;
26+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m3 = #C11;
27+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m4 = #C12;
28+
static const field core::Map<core::int, core::int> m34i = #C13;
29+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m43 = #C14;
30+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m3s4 = #C13;
31+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> ms43 = #C14;
32+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> ms3s4 = #C13;
33+
static extension-type-member method ExInt|constructor#(core::int _) → self::ExInt /* = core::int */ {
34+
lowered final self::ExInt /* = core::int */ #this = _;
35+
return #this;
36+
}
37+
static extension-type-member method ExInt|constructor#_#new#tearOff(core::int _) → self::ExInt /* = core::int */
38+
return self::ExInt|constructor#(_);
39+
40+
constants {
41+
#C1 = 3
42+
#C2 = 4
43+
#C3 = <core::int>[#C1]
44+
#C4 = <core::int>[#C2]
45+
#C5 = <core::int>[#C1, #C2]
46+
#C6 = <core::int>[#C2, #C1]
47+
#C7 = <core::int>{#C1}
48+
#C8 = <core::int>{#C2}
49+
#C9 = <core::int>{#C1, #C2}
50+
#C10 = <core::int>{#C2, #C1}
51+
#C11 = <core::int, core::int>{#C1:#C1}
52+
#C12 = <core::int, core::int>{#C2:#C2}
53+
#C13 = <core::int, core::int>{#C1:#C1, #C2:#C2}
54+
#C14 = <core::int, core::int>{#C2:#C2, #C1:#C1}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
extension type ExInt(core::int _) implements core::int {
6+
abstract extension-type-member representation-field get _() → core::int;
7+
constructor • = self::ExInt|constructor#;
8+
constructor tearoff • = self::ExInt|constructor#_#new#tearOff;
9+
}
10+
static const field self::ExInt /* = core::int */ ex3 = #C1;
11+
static const field self::ExInt /* = core::int */ ex4 = #C2;
12+
static const field core::List<self::ExInt /* = core::int */> l3 = #C3;
13+
static const field core::List<self::ExInt /* = core::int */> l4 = #C4;
14+
static const field core::List<core::int> l34i = #C5;
15+
static const field core::List<self::ExInt /* = core::int */> l43 = #C6;
16+
static const field core::List<self::ExInt /* = core::int */> l3s4 = #C5;
17+
static const field core::List<self::ExInt /* = core::int */> ls43 = #C6;
18+
static const field core::List<self::ExInt /* = core::int */> ls3s4 = #C5;
19+
static const field core::Set<self::ExInt /* = core::int */> s3 = #C7;
20+
static const field core::Set<self::ExInt /* = core::int */> s4 = #C8;
21+
static const field core::Set<core::int> s34i = #C9;
22+
static const field core::Set<self::ExInt /* = core::int */> s43 = #C10;
23+
static const field core::Set<self::ExInt /* = core::int */> s3s4 = #C9;
24+
static const field core::Set<self::ExInt /* = core::int */> ss43 = #C10;
25+
static const field core::Set<self::ExInt /* = core::int */> ss3s4 = #C9;
26+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m3 = #C11;
27+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m4 = #C12;
28+
static const field core::Map<core::int, core::int> m34i = #C13;
29+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m43 = #C14;
30+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m3s4 = #C13;
31+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> ms43 = #C14;
32+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> ms3s4 = #C13;
33+
static extension-type-member method ExInt|constructor#(core::int _) → self::ExInt /* = core::int */ {
34+
lowered final self::ExInt /* = core::int */ #this = _;
35+
return #this;
36+
}
37+
static extension-type-member method ExInt|constructor#_#new#tearOff(core::int _) → self::ExInt /* = core::int */
38+
return self::ExInt|constructor#(_);
39+
40+
constants {
41+
#C1 = 3
42+
#C2 = 4
43+
#C3 = <core::int>[#C1]
44+
#C4 = <core::int>[#C2]
45+
#C5 = <core::int>[#C1, #C2]
46+
#C6 = <core::int>[#C2, #C1]
47+
#C7 = <core::int>{#C1}
48+
#C8 = <core::int>{#C2}
49+
#C9 = <core::int>{#C1, #C2}
50+
#C10 = <core::int>{#C2, #C1}
51+
#C11 = <core::int, core::int>{#C1:#C1}
52+
#C12 = <core::int, core::int>{#C2:#C2}
53+
#C13 = <core::int, core::int>{#C1:#C1, #C2:#C2}
54+
#C14 = <core::int, core::int>{#C2:#C2, #C1:#C1}
55+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const ex3 = ExInt(3);
2+
const ex4 = ExInt(4);
3+
const l3 = [ex3];
4+
const l4 = [ex4];
5+
const l34i = [ex3 as int, ...l4 as List<int>];
6+
const l43 = [ex4, ex3];
7+
const l3s4 = [ex3, ...l4];
8+
const ls43 = [...l4, ex3];
9+
const ls3s4 = [...l3, ...l4];
10+
const s3 = {ex3};
11+
const s4 = {ex4};
12+
const s34i = {ex3 as int, ...s4 as Set<int>};
13+
const s43 = {ex4, ex3};
14+
const s3s4 = {ex3, ...s4};
15+
const ss43 = {...s4, ex3};
16+
const ss3s4 = {...s3, ...s4};
17+
const m3 = {ex3: ex3};
18+
const m4 = {ex4: ex4};
19+
const m34i = {ex3 as int: ex3 as int, ...m4 as Map<int, int>};
20+
const m43 = {ex4: ex4, ex3: ex3};
21+
const m3s4 = {ex3: ex3, ...m4};
22+
const ms43 = {...m4, ex3: ex3};
23+
const ms3s4 = {...m3, ...m4};
24+
extension type const ExInt(int _) implements int {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const ex3 = ExInt(3);
2+
const ex4 = ExInt(4);
3+
const l3 = [ex3];
4+
const l34i = [ex3 as int, ...l4 as List<int>];
5+
const l3s4 = [ex3, ...l4];
6+
const l4 = [ex4];
7+
const l43 = [ex4, ex3];
8+
const ls3s4 = [...l3, ...l4];
9+
const ls43 = [...l4, ex3];
10+
const m3 = {ex3: ex3};
11+
const m34i = {ex3 as int: ex3 as int, ...m4 as Map<int, int>};
12+
const m3s4 = {ex3: ex3, ...m4};
13+
const m4 = {ex4: ex4};
14+
const m43 = {ex4: ex4, ex3: ex3};
15+
const ms3s4 = {...m3, ...m4};
16+
const ms43 = {...m4, ex3: ex3};
17+
const s3 = {ex3};
18+
const s34i = {ex3 as int, ...s4 as Set<int>};
19+
const s3s4 = {ex3, ...s4};
20+
const s4 = {ex4};
21+
const s43 = {ex4, ex3};
22+
const ss3s4 = {...s3, ...s4};
23+
const ss43 = {...s4, ex3};
24+
extension type const ExInt(int _) implements int {}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
extension type ExInt(core::int _) implements core::int {
6+
abstract extension-type-member representation-field get _() → core::int;
7+
constructor • = self::ExInt|constructor#;
8+
constructor tearoff • = self::ExInt|constructor#_#new#tearOff;
9+
}
10+
static const field self::ExInt /* = core::int */ ex3 = #C1;
11+
static const field self::ExInt /* = core::int */ ex4 = #C2;
12+
static const field core::List<self::ExInt /* = core::int */> l3 = #C3;
13+
static const field core::List<self::ExInt /* = core::int */> l4 = #C4;
14+
static const field core::List<core::int> l34i = #C5;
15+
static const field core::List<self::ExInt /* = core::int */> l43 = #C6;
16+
static const field core::List<self::ExInt /* = core::int */> l3s4 = #C5;
17+
static const field core::List<self::ExInt /* = core::int */> ls43 = #C6;
18+
static const field core::List<self::ExInt /* = core::int */> ls3s4 = #C5;
19+
static const field core::Set<self::ExInt /* = core::int */> s3 = #C7;
20+
static const field core::Set<self::ExInt /* = core::int */> s4 = #C8;
21+
static const field core::Set<core::int> s34i = #C9;
22+
static const field core::Set<self::ExInt /* = core::int */> s43 = #C10;
23+
static const field core::Set<self::ExInt /* = core::int */> s3s4 = #C9;
24+
static const field core::Set<self::ExInt /* = core::int */> ss43 = #C10;
25+
static const field core::Set<self::ExInt /* = core::int */> ss3s4 = #C9;
26+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m3 = #C11;
27+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m4 = #C12;
28+
static const field core::Map<core::int, core::int> m34i = #C13;
29+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m43 = #C14;
30+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m3s4 = #C13;
31+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> ms43 = #C14;
32+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> ms3s4 = #C13;
33+
static extension-type-member method ExInt|constructor#(core::int _) → self::ExInt /* = core::int */ {
34+
lowered final self::ExInt /* = core::int */ #this = _;
35+
return #this;
36+
}
37+
static extension-type-member method ExInt|constructor#_#new#tearOff(core::int _) → self::ExInt /* = core::int */
38+
return self::ExInt|constructor#(_);
39+
40+
constants {
41+
#C1 = 3
42+
#C2 = 4
43+
#C3 = <core::int*>[#C1]
44+
#C4 = <core::int*>[#C2]
45+
#C5 = <core::int*>[#C1, #C2]
46+
#C6 = <core::int*>[#C2, #C1]
47+
#C7 = <core::int*>{#C1}
48+
#C8 = <core::int*>{#C2}
49+
#C9 = <core::int*>{#C1, #C2}
50+
#C10 = <core::int*>{#C2, #C1}
51+
#C11 = <core::int*, core::int*>{#C1:#C1}
52+
#C12 = <core::int*, core::int*>{#C2:#C2}
53+
#C13 = <core::int*, core::int*>{#C1:#C1, #C2:#C2}
54+
#C14 = <core::int*, core::int*>{#C2:#C2, #C1:#C1}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
extension type ExInt(core::int _) implements core::int {
6+
abstract extension-type-member representation-field get _() → core::int;
7+
constructor • = self::ExInt|constructor#;
8+
constructor tearoff • = self::ExInt|constructor#_#new#tearOff;
9+
}
10+
static const field self::ExInt /* = core::int */ ex3 = #C1;
11+
static const field self::ExInt /* = core::int */ ex4 = #C2;
12+
static const field core::List<self::ExInt /* = core::int */> l3 = #C3;
13+
static const field core::List<self::ExInt /* = core::int */> l4 = #C4;
14+
static const field core::List<core::int> l34i = #C5;
15+
static const field core::List<self::ExInt /* = core::int */> l43 = #C6;
16+
static const field core::List<self::ExInt /* = core::int */> l3s4 = #C5;
17+
static const field core::List<self::ExInt /* = core::int */> ls43 = #C6;
18+
static const field core::List<self::ExInt /* = core::int */> ls3s4 = #C5;
19+
static const field core::Set<self::ExInt /* = core::int */> s3 = #C7;
20+
static const field core::Set<self::ExInt /* = core::int */> s4 = #C8;
21+
static const field core::Set<core::int> s34i = #C9;
22+
static const field core::Set<self::ExInt /* = core::int */> s43 = #C10;
23+
static const field core::Set<self::ExInt /* = core::int */> s3s4 = #C9;
24+
static const field core::Set<self::ExInt /* = core::int */> ss43 = #C10;
25+
static const field core::Set<self::ExInt /* = core::int */> ss3s4 = #C9;
26+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m3 = #C11;
27+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m4 = #C12;
28+
static const field core::Map<core::int, core::int> m34i = #C13;
29+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m43 = #C14;
30+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> m3s4 = #C13;
31+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> ms43 = #C14;
32+
static const field core::Map<self::ExInt /* = core::int */, self::ExInt /* = core::int */> ms3s4 = #C13;
33+
static extension-type-member method ExInt|constructor#(core::int _) → self::ExInt /* = core::int */ {
34+
lowered final self::ExInt /* = core::int */ #this = _;
35+
return #this;
36+
}
37+
static extension-type-member method ExInt|constructor#_#new#tearOff(core::int _) → self::ExInt /* = core::int */
38+
return self::ExInt|constructor#(_);
39+
40+
constants {
41+
#C1 = 3
42+
#C2 = 4
43+
#C3 = <core::int*>[#C1]
44+
#C4 = <core::int*>[#C2]
45+
#C5 = <core::int*>[#C1, #C2]
46+
#C6 = <core::int*>[#C2, #C1]
47+
#C7 = <core::int*>{#C1}
48+
#C8 = <core::int*>{#C2}
49+
#C9 = <core::int*>{#C1, #C2}
50+
#C10 = <core::int*>{#C2, #C1}
51+
#C11 = <core::int*, core::int*>{#C1:#C1}
52+
#C12 = <core::int*, core::int*>{#C2:#C2}
53+
#C13 = <core::int*, core::int*>{#C1:#C1, #C2:#C2}
54+
#C14 = <core::int*, core::int*>{#C2:#C2, #C1:#C1}
55+
}

0 commit comments

Comments
 (0)