forked from flutter/engine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I464275799b3e7a21326d35503b776f9c1101a599 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141764 Commit-Queue: Bob Nystrom <rnystrom@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com> Reviewed-by: Erik Ernst <eernst@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com>
- Loading branch information
1 parent
1d44ef0
commit e736495
Showing
88 changed files
with
3,134 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// Implicit casts in constants are supported and treated as compile-time errors | ||
/// if they are not valid. | ||
class A { | ||
final int n; | ||
const A(dynamic input) : n = input; | ||
} | ||
|
||
main() { | ||
print(const A(2)); //# 01: ok | ||
print(const A('2')); //# 02: compile-time error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// Explicit casts in constants are supported and treated as compile-time errors | ||
/// if they are not valid. | ||
class A { | ||
final int n; | ||
const A(dynamic input) : n = input as int; | ||
} | ||
|
||
main() { | ||
print(const A(2)); //# 01: ok | ||
print(const A('2')); //# 02: compile-time error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// Casts in constants correctly substitute type variables. | ||
class A { | ||
const A(); | ||
} | ||
|
||
class B implements A { | ||
const B(); | ||
} | ||
|
||
class M<T extends A> { | ||
final T a; | ||
const M(dynamic t) : a = t; // adds implicit cast `as T` | ||
} | ||
|
||
main() { | ||
print(const M<B>(const B())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// Casts in constants correctly substitute type variables. | ||
class A { | ||
const A(); | ||
} | ||
|
||
class B implements A { | ||
const B(); | ||
} | ||
|
||
class M<T extends A> { | ||
final T a; | ||
const M(dynamic t) : a = t; // adds implicit cast `as T` | ||
} | ||
|
||
class N<S extends A> extends M<S> { | ||
const N(dynamic t) : super(t); | ||
} | ||
|
||
main() { | ||
print(const N<B>(const B())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// TODO(multitest): This was automatically migrated from a multitest and may | ||
// contain strange or dead code. | ||
|
||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Test for conditionals as compile-time constants. | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
class Marker { | ||
final field; | ||
const Marker(this.field); | ||
} | ||
|
||
var var0 = const Marker(0); | ||
var var1 = const Marker(1); | ||
const const0 = const Marker(0); | ||
const const1 = const Marker(1); | ||
|
||
const trueConst = true; | ||
const falseConst = false; | ||
var nonConst = true; | ||
const zeroConst = 0; | ||
|
||
const cond1 = trueConst ? const0 : const1; | ||
|
||
|
||
|
||
const cond2 = falseConst ? const0 : const1; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
void main() { | ||
Expect.identical(var0, cond1); | ||
|
||
|
||
|
||
Expect.identical(var1, cond2); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Test for conditionals as compile-time constants. | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
class Marker { | ||
final field; | ||
const Marker(this.field); | ||
} | ||
|
||
var var0 = const Marker(0); | ||
var var1 = const Marker(1); | ||
const const0 = const Marker(0); | ||
const const1 = const Marker(1); | ||
|
||
const trueConst = true; | ||
const falseConst = false; | ||
var nonConst = true; | ||
const zeroConst = 0; | ||
|
||
const cond1 = trueConst ? const0 : const1; | ||
const cond1a = trueConst ? nonConst : const1; | ||
// ^ | ||
// [cfe] Constant evaluation error: | ||
// ^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | ||
// [cfe] Not a constant expression. | ||
const cond1b = trueConst ? const0 : nonConst; | ||
// ^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | ||
// [cfe] Not a constant expression. | ||
|
||
const cond2 = falseConst ? const0 : const1; | ||
const cond2a = falseConst ? nonConst : const1; | ||
// ^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | ||
// [cfe] Not a constant expression. | ||
const cond2b = falseConst ? const0 : nonConst; | ||
// ^ | ||
// [cfe] Constant evaluation error: | ||
// ^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | ||
// [cfe] Not a constant expression. | ||
|
||
const cond3 = nonConst ? const0 : const1; | ||
// ^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | ||
// [cfe] Not a constant expression. | ||
// ^ | ||
// [cfe] Constant evaluation error: | ||
const cond3a = nonConst ? nonConst : const1; | ||
// ^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | ||
// [cfe] Not a constant expression. | ||
// ^ | ||
// [cfe] Constant evaluation error: | ||
// ^ | ||
// [cfe] Not a constant expression. | ||
const cond3b = nonConst ? const0 : nonConst; | ||
// ^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | ||
// [cfe] Not a constant expression. | ||
// ^ | ||
// [cfe] Constant evaluation error: | ||
// ^ | ||
// [cfe] Not a constant expression. | ||
|
||
const cond4 = zeroConst ? const0 : const1; | ||
// ^^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_TYPE_BOOL | ||
// [cfe] A value of type 'int' can't be assigned to a variable of type 'bool'. | ||
// ^^^^^^^^^ | ||
// [analyzer] STATIC_TYPE_WARNING.NON_BOOL_CONDITION | ||
const cond4a = zeroConst ? nonConst : const1; | ||
// ^^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_TYPE_BOOL | ||
// [cfe] A value of type 'int' can't be assigned to a variable of type 'bool'. | ||
// ^^^^^^^^^ | ||
// [analyzer] STATIC_TYPE_WARNING.NON_BOOL_CONDITION | ||
// ^ | ||
// [cfe] Not a constant expression. | ||
const cond4b = zeroConst ? const0 : nonConst; | ||
// ^^^^^^^^^ | ||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_TYPE_BOOL | ||
// [cfe] A value of type 'int' can't be assigned to a variable of type 'bool'. | ||
// ^^^^^^^^^ | ||
// [analyzer] STATIC_TYPE_WARNING.NON_BOOL_CONDITION | ||
// ^ | ||
// [cfe] Not a constant expression. | ||
|
||
void main() { | ||
Expect.identical(var0, cond1); | ||
Expect.identical(nonConst, cond1a); | ||
Expect.identical(var0, cond1b); | ||
|
||
Expect.identical(var1, cond2); | ||
Expect.identical(var1, cond2a); | ||
Expect.identical(nonConst, cond2b); | ||
|
||
Expect.identical(var0, cond3); | ||
Expect.identical(nonConst, cond3a); | ||
Expect.identical(var0, cond3b); | ||
|
||
Expect.identical(var1, cond4); | ||
Expect.identical(var1, cond4a); | ||
Expect.identical(nonConst, cond4b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
// VMOptions= | ||
// VMOptions=--compile_all | ||
|
||
// Exercises language constructs that require compile time constants | ||
|
||
// Initialize with different literal types | ||
const b = true; | ||
const s = "apple"; | ||
const i = 1; | ||
const d = 3.3; | ||
const h = 0xf; | ||
const n = null; | ||
const aList = const [1, 2, 3]; // array literal | ||
const aMap = const {"1": "one", "2": "banana"}; // map literal | ||
|
||
const INT_LIT = 5; | ||
const INT_LIT_REF = INT_LIT; | ||
const DOUBLE_LIT = 1.5; | ||
const BOOL_LIT = true; | ||
const STRING_LIT = "Hello"; | ||
|
||
const BOP1_0 = INT_LIT + 1; | ||
const BOP1_1 = 1 + INT_LIT; | ||
const BOP1_2 = INT_LIT - 1; | ||
const BOP1_3 = 1 - INT_LIT; | ||
const BOP1_4 = INT_LIT * 1; | ||
const BOP1_5 = 1 * INT_LIT; | ||
const BOP1_6 = INT_LIT / 1; | ||
const BOP1_7 = 1 / INT_LIT; | ||
const BOP2_0 = DOUBLE_LIT + 1.5; | ||
const BOP2_1 = 1.5 + DOUBLE_LIT; | ||
const BOP2_2 = DOUBLE_LIT - 1.5; | ||
const BOP2_3 = 1.5 - DOUBLE_LIT; | ||
const BOP2_4 = DOUBLE_LIT * 1.5; | ||
const BOP2_5 = 1.5 * DOUBLE_LIT; | ||
const BOP2_6 = DOUBLE_LIT / 1.5; | ||
const BOP2_7 = 1.5 / DOUBLE_LIT; | ||
const BOP3_0 = 2 < INT_LIT; | ||
const BOP3_1 = INT_LIT < 2; | ||
const BOP3_2 = 2 > INT_LIT; | ||
const BOP3_3 = INT_LIT > 2; | ||
const BOP3_4 = 2 < DOUBLE_LIT; | ||
const BOP3_5 = DOUBLE_LIT < 2; | ||
const BOP3_6 = 2 > DOUBLE_LIT; | ||
const BOP3_7 = DOUBLE_LIT > 2; | ||
const BOP3_8 = 2 <= INT_LIT; | ||
const BOP3_9 = INT_LIT <= 2; | ||
const BOP3_10 = 2 >= INT_LIT; | ||
const BOP3_11 = INT_LIT >= 2; | ||
const BOP3_12 = 2.0 <= DOUBLE_LIT; | ||
const BOP3_13 = DOUBLE_LIT <= 2.0; | ||
const BOP3_14 = 2.0 >= DOUBLE_LIT; | ||
const BOP3_15 = DOUBLE_LIT >= 2; | ||
const BOP4_0 = 5 % INT_LIT; | ||
const BOP4_1 = INT_LIT % 5; | ||
const BOP4_2 = 5.0 % DOUBLE_LIT; | ||
const BOP4_3 = DOUBLE_LIT % 5.0; | ||
const BOP5_0 = 0x80 & 0x04; | ||
const BOP5_1 = 0x80 | 0x04; | ||
const BOP5_2 = 0x80 << 0x04; | ||
const BOP5_3 = 0x80 >> 0x04; | ||
const BOP5_4 = 0x80 ~/ 0x04; | ||
const BOP5_5 = 0x80 ^ 0x04; | ||
const BOP6 = BOOL_LIT && true; | ||
const BOP7 = false || BOOL_LIT; | ||
const BOP8 = STRING_LIT == "World!"; | ||
const BOP9 = "Hello" != STRING_LIT; | ||
const BOP10 = INT_LIT == INT_LIT_REF; | ||
const BOP11 = BOOL_LIT != true; | ||
|
||
// Multiple binary expressions | ||
const BOP20 = 1 * INT_LIT / 3 + INT_LIT + 9; | ||
|
||
// Parenthised expressions | ||
const BOP30 = (1 > 2); | ||
const BOP31 = (1 * 2) + 3; | ||
const BOP32 = 3 + (1 * 2); | ||
|
||
// Unary expressions | ||
const UOP1_0 = !BOOL_LIT; | ||
const UOP1_1 = BOOL_LIT || !true; | ||
const UOP1_2 = !BOOL_LIT || true; | ||
const UOP1_3 = !(BOOL_LIT && true); | ||
const UOP2_0 = ~0xf0; | ||
const UOP2_1 = ~INT_LIT; | ||
const UOP2_2 = ~INT_LIT & 123; | ||
const UOP2_3 = ~(INT_LIT | 0xff); | ||
const UOP3_0 = -0xf0; | ||
const UOP3_1 = -INT_LIT; | ||
const UOP3_2 = -INT_LIT + 123; | ||
const UOP3_3 = -(INT_LIT * 0xff); | ||
const UOP3_4 = -0xf0; | ||
const UOP3_5 = -DOUBLE_LIT; | ||
const UOP3_6 = -DOUBLE_LIT + 123; | ||
const UOP3_7 = -(DOUBLE_LIT * 0xff); | ||
|
||
class A { | ||
const A(); | ||
static const a = const A(); // Assignment from Constant constructor OK | ||
} | ||
|
||
main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
// Check that initializers of const fields can be declared out of order. | ||
|
||
import "package:expect/expect.dart"; | ||
|
||
const P = 2 * (O - N); | ||
const N = 1; | ||
const O = 1 + 3; | ||
|
||
void main() { | ||
Expect.equals(1, N); | ||
Expect.equals(4, O); | ||
Expect.equals(6, P); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
// See CTConst4Test.dart | ||
|
||
library CTConst4Lib; | ||
|
||
const B = 1; |
Oops, something went wrong.