Skip to content

Commit 0214c58

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Add test for issue 47154
Closes #47154 Change-Id: I23ad2582a2f90c081066870bcd64890c71c5b421 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213040 Reviewed-by: Dmitry Stefantsov <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent a4a1f2c commit 0214c58

17 files changed

+372
-0
lines changed

pkg/front_end/test/spell_checking_list_tests.txt

+1
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ timeout
926926
timer
927927
timings
928928
tinv
929+
tk
929930
told
930931
touch
931932
tpt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2021, 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+
class A {
6+
final int Function(int) x;
7+
const A(bool b)
8+
: x = (b
9+
? id
10+
: other)<int>; // OK, `(...)<T1..Tk>` is potentially constant.
11+
}
12+
13+
X id<X>(X x) => x;
14+
X other<X>(X x) => throw '$x';
15+
16+
void main() {
17+
const c1 =
18+
id<int>; // Already supported prior to the addition on this feature.
19+
const c2 =
20+
id; // Make `c2` a constant expression whose value is a function object.
21+
const c3 = c2<int>; // OK, perform generic function instantiation on `c2`.
22+
const c4 = A(
23+
true); // OK, `(b ? id : other)<int>` is constant after substitution `b` -> `true`.
24+
print('$c1, $c2, $c3, $c4');
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = (b ?{<X extends core::Object? = dynamic>(X%) → X%} #C1 : #C2)<core::int>, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
return x;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
return throw "${x}";
15+
static method main() → void {
16+
core::print("${#C3}, ${#C1}, ${#C3}, ${#C4}");
17+
}
18+
19+
constants {
20+
#C1 = static-tearoff self::id
21+
#C2 = static-tearoff self::other
22+
#C3 = instantiation self::id <core::int>
23+
#C4 = self::A {x:#C3}
24+
}
25+
26+
27+
Constructor coverage from constants:
28+
org-dartlang-testcase:///issue47154a.dart:
29+
- A. (from org-dartlang-testcase:///issue47154a.dart:7:9)
30+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = (b ?{<X extends core::Object? = dynamic>(X%) → X%} #C1 : #C2)<core::int>, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
return x;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
return throw "${x}";
15+
static method main() → void {
16+
core::print("${#C3}, ${#C1}, ${#C3}, ${#C4}");
17+
}
18+
19+
constants {
20+
#C1 = static-tearoff self::id
21+
#C2 = static-tearoff self::other
22+
#C3 = instantiation self::id <core::int>
23+
#C4 = self::A {x:#C3}
24+
}
25+
26+
27+
Constructor coverage from constants:
28+
org-dartlang-testcase:///issue47154a.dart:
29+
- A. (from org-dartlang-testcase:///issue47154a.dart:7:9)
30+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A {
2+
final int Function(int) x;
3+
const A(bool b) : x = (b ? id : other)<int>;
4+
}
5+
6+
X id<X>(X x) => x;
7+
X other<X>(X x) => throw '$x';
8+
void main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
X id<X>(X x) => x;
2+
X other<X>(X x) => throw '$x';
3+
4+
class A {
5+
const A(bool b) : x = (b ? id : other)<int>;
6+
final int Function(int) x;
7+
}
8+
9+
void main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = (b ?{<X extends core::Object? = dynamic>(X%) → X%} #C1 : #C2)<core::int>, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
return x;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
return throw "${x}";
15+
static method main() → void {
16+
core::print("${#C3}, ${#C1}, ${#C3}, ${#C4}");
17+
}
18+
19+
constants {
20+
#C1 = static-tearoff self::id
21+
#C2 = static-tearoff self::other
22+
#C3 = instantiation self::id <core::int*>
23+
#C4 = self::A {x:#C3}
24+
}
25+
26+
27+
Constructor coverage from constants:
28+
org-dartlang-testcase:///issue47154a.dart:
29+
- A. (from org-dartlang-testcase:///issue47154a.dart:7:9)
30+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = (b ?{<X extends core::Object? = dynamic>(X%) → X%} self::id : self::other)<core::int>, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
;
15+
static method main() → void
16+
;
17+
18+
19+
Extra constant evaluation status:
20+
Evaluated: StaticTearOff @ org-dartlang-testcase:///issue47154a.dart:9:15 -> StaticTearOffConstant(id)
21+
Evaluated: StaticTearOff @ org-dartlang-testcase:///issue47154a.dart:10:15 -> StaticTearOffConstant(other)
22+
Extra constant evaluation: evaluated: 5, effectively constant: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = (b ?{<X extends core::Object? = dynamic>(X%) → X%} #C1 : #C2)<core::int>, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
return x;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
return throw "${x}";
15+
static method main() → void {
16+
core::print("${#C3}, ${#C1}, ${#C3}, ${#C4}");
17+
}
18+
19+
constants {
20+
#C1 = static-tearoff self::id
21+
#C2 = static-tearoff self::other
22+
#C3 = instantiation self::id <core::int*>
23+
#C4 = self::A {x:#C3}
24+
}
25+
26+
27+
Constructor coverage from constants:
28+
org-dartlang-testcase:///issue47154a.dart:
29+
- A. (from org-dartlang-testcase:///issue47154a.dart:7:9)
30+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2021, 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+
class A {
6+
final int Function(int) x;
7+
const A(bool b)
8+
: x = (b ? id : other); // OK, `(...)<T1..Tk>` is potentially constant.
9+
}
10+
11+
X id<X>(X x) => x;
12+
X other<X>(X x) => throw '$x';
13+
14+
void main() {
15+
const int Function(int) c1 =
16+
id; // Already supported prior to the addition on this feature.
17+
const c2 =
18+
id; // Make `c2` a constant expression whose value is a function object.
19+
const int Function(int) c3 =
20+
c2; // OK, perform generic function instantiation on `c2`.
21+
const c4 = A(
22+
true); // OK, `(b ? id : other)<int>` is constant after substitution `b` -> `true`.
23+
print('$c1, $c2, $c3, $c4');
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = b ?{(core::int) → core::int} #C2 : #C4, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
return x;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
return throw "${x}";
15+
static method main() → void {
16+
core::print("${#C2}, ${#C1}, ${#C2}, ${#C5}");
17+
}
18+
19+
constants {
20+
#C1 = static-tearoff self::id
21+
#C2 = instantiation self::id <core::int>
22+
#C3 = static-tearoff self::other
23+
#C4 = instantiation self::other <core::int>
24+
#C5 = self::A {x:#C2}
25+
}
26+
27+
28+
Constructor coverage from constants:
29+
org-dartlang-testcase:///issue47154b.dart:
30+
- A. (from org-dartlang-testcase:///issue47154b.dart:7:9)
31+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = b ?{(core::int) → core::int} #C2 : #C4, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
return x;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
return throw "${x}";
15+
static method main() → void {
16+
core::print("${#C2}, ${#C1}, ${#C2}, ${#C5}");
17+
}
18+
19+
constants {
20+
#C1 = static-tearoff self::id
21+
#C2 = instantiation self::id <core::int>
22+
#C3 = static-tearoff self::other
23+
#C4 = instantiation self::other <core::int>
24+
#C5 = self::A {x:#C2}
25+
}
26+
27+
28+
Constructor coverage from constants:
29+
org-dartlang-testcase:///issue47154b.dart:
30+
- A. (from org-dartlang-testcase:///issue47154b.dart:7:9)
31+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A {
2+
final int Function(int) x;
3+
const A(bool b) : x = (b ? id : other);
4+
}
5+
6+
X id<X>(X x) => x;
7+
X other<X>(X x) => throw '$x';
8+
void main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
X id<X>(X x) => x;
2+
X other<X>(X x) => throw '$x';
3+
4+
class A {
5+
const A(bool b) : x = (b ? id : other);
6+
final int Function(int) x;
7+
}
8+
9+
void main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = b ?{(core::int) → core::int} #C2 : #C4, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
return x;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
return throw "${x}";
15+
static method main() → void {
16+
core::print("${#C2}, ${#C1}, ${#C2}, ${#C5}");
17+
}
18+
19+
constants {
20+
#C1 = static-tearoff self::id
21+
#C2 = instantiation self::id <core::int*>
22+
#C3 = static-tearoff self::other
23+
#C4 = instantiation self::other <core::int*>
24+
#C5 = self::A {x:#C2}
25+
}
26+
27+
28+
Constructor coverage from constants:
29+
org-dartlang-testcase:///issue47154b.dart:
30+
- A. (from org-dartlang-testcase:///issue47154b.dart:7:9)
31+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = b ?{(core::int) → core::int} self::id<core::int> : self::other<core::int>, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
;
15+
static method main() → void
16+
;
17+
18+
19+
Extra constant evaluation status:
20+
Evaluated: Instantiation @ org-dartlang-testcase:///issue47154b.dart:8:18 -> InstantiationConstant(id<int*>)
21+
Evaluated: Instantiation @ org-dartlang-testcase:///issue47154b.dart:8:23 -> InstantiationConstant(other<int*>)
22+
Extra constant evaluation: evaluated: 4, effectively constant: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A extends core::Object /*hasConstConstructor*/ {
6+
final field (core::int) → core::int x;
7+
const constructor •(core::bool b) → self::A
8+
: self::A::x = b ?{(core::int) → core::int} #C2 : #C4, super core::Object::•()
9+
;
10+
}
11+
static method id<X extends core::Object? = dynamic>(self::id::X% x) → self::id::X%
12+
return x;
13+
static method other<X extends core::Object? = dynamic>(self::other::X% x) → self::other::X%
14+
return throw "${x}";
15+
static method main() → void {
16+
core::print("${#C2}, ${#C1}, ${#C2}, ${#C5}");
17+
}
18+
19+
constants {
20+
#C1 = static-tearoff self::id
21+
#C2 = instantiation self::id <core::int*>
22+
#C3 = static-tearoff self::other
23+
#C4 = instantiation self::other <core::int*>
24+
#C5 = self::A {x:#C2}
25+
}
26+
27+
28+
Constructor coverage from constants:
29+
org-dartlang-testcase:///issue47154b.dart:
30+
- A. (from org-dartlang-testcase:///issue47154b.dart:7:9)
31+
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9)

0 commit comments

Comments
 (0)