Files
sdk/tests/language_2/spread_collections/const_error_test.dart
T
Kevin Millikin 64b0ce5b58 Remove UI as code experimental flags from our tests
The features control-flow-collections and spread-collections have been
shipped and it is no longer necessary for tests to explicitly opt into
them.

Change-Id: I074b91d12e4e485ee4a64147947bb1113899ecdc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/104780
Auto-Submit: Kevin Millikin <kmillikin@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Kevin Millikin <kmillikin@google.com>
2019-06-06 13:17:49 +00:00

68 lines
1.9 KiB
Dart

// 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.
// SharedOptions=--enable-experiment=constant-update-2018
import 'dart:collection';
import 'helper_classes.dart';
var nonConstList = <int>[];
var nonConstMap = <int, String>{};
const dynamic nonIterable = 3;
const dynamic nonMap = 3;
void main() {
testList();
testMap();
testSet();
}
void testList() {
// Must be constant.
const _ = <int>[...nonConstList]; //# 01: compile-time error
// Must be iterable.
const _ = <int>[...nonIterable]; //# 02: compile-time error
// Cannot be custom iterable type.
const _ = <int>[...ConstIterable()]; //# 03: compile-time error
}
void testMap() {
// Must be constant.
const _ = <int, String>{...nonConstMap}; //# 04: compile-time error
// Must be map.
const _ = <int, String>{...nonMap}; //# 05: compile-time error
// Cannot be custom map type.
const _ = <int, String>{...ConstMap()}; //# 06: compile-time error
// Cannot have key collision.
const _ = <int, String>{1: "s", ...{1: "t"}}; //# 07: compile-time error
const _ = <int, String>{...{1: "s"}, ...{1: "t"}}; //# 08: compile-time error
}
void testSet() {
// Must be constant.
const _ = <int>{...nonConstList}; //# 09: compile-time error
// Must be iterable.
const _ = <int>{...nonIterable}; //# 10: compile-time error
// Cannot be custom iterable type.
const _ = <int>{...ConstIterable()}; //# 11: compile-time error
// Cannot override operator.==().
const obj = 0.1;
const _ = {...[0.1]}; //# 12: compile-time error
const _ = {...[Duration(seconds: 0)]}; //# 13: compile-time error
const _ = {...[obj]}; //# 14: compile-time error
// Cannot have collision.
const _ = {1, ...[1]}; //# 15: compile-time error
const _ = {...[1], ...[1]}; //# 16: compile-time error
}