blob: 3c063163eb3104518d43a4bed42ebc409d27ed26 [file] [log] [blame]
// Copyright (c) 2019, 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.
/**
* @assertion From the Unified collection Spec:
* A [spreadElement] starting with [...?] is a constant element if its
* expression is constant and it evaluates to [null] or a constant [List], [Set]
* or [Map] instance originally created by a list, set or map literal. It is a
* potentially constant element if the expression is potentially constant
* expression.
* @description: Checks that constant list [...?] spread element can only be
* potentially constant list or set or [null].
* @author iarkh@unipro.ru
*/
class MyClass {
final String a;
const MyClass(Object o) : a = o as String;
}
main() {
const List l1 = [...?(MyClass(12345) is MyClass ? [12] : [])];
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
const List l2 = [...?(MyClass(12345) is MyClass ? {12} : {2})];
// ^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
const List l3 = [...?(MyClass(12345) is MyClass ? {12} : null)];
// ^
// [cfe] Constant evaluation error:
// ^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_THROWS_EXCEPTION
const List l4 = [...?(MyClass(12345) is MyClass ? {null} : 1)];
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}