Add tests for trailing commas in set literals.
Change-Id: I42e361e7c8fef21c30e5bfcc514be44a2f0ed801
Reviewed-on: https://dart-review.googlesource.com/c/84632
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
diff --git a/tests/language_2/set_literals/invalid_set_literal_test.dart b/tests/language_2/set_literals/invalid_set_literal_test.dart
index 7facd60..edce343 100644
--- a/tests/language_2/set_literals/invalid_set_literal_test.dart
+++ b/tests/language_2/set_literals/invalid_set_literal_test.dart
@@ -8,8 +8,9 @@
import "package:expect/expect.dart";
-void main() {
- var o //
+const Object d = 3.5;
+
+void main() var o //
= <int>{1: 1} //# 01: compile-time error
= <int, int, int>{} //# 02: compile-time error
= <int, int, int>{1} //# 03: compile-time error
@@ -18,38 +19,52 @@
= const <int, int, int>{1} //# 06: compile-time error
= const <int, int>{1} //# 07: compile-time error
= const {Duration(seconds: 0)} // Overrides ==. //# 08: compile-time error
+ = {4.2} // Overrides ==. //# 09: compile-time error
+ = {d} // Overrides ==. //# 10: compile-time error
+ = {,} //# 11: compile-time error
+ = {1,,} //# 12: compile-time error
+ = {1,,1} //# 13: compile-time error
;
Expect.isNull(o); // Should be unreachable with a value.
Set<int> s //
- = {"not int"} //# 09: compile-time error
- = {4.2} //# 10: compile-time error
- = {1: 1} //# 11: compile-time error
- = {{}} //# 12: compile-time error
- = <Object>{} // Exact type. //# 13: compile-time error
+ = {"not int"} //# 14: compile-time error
+ = {4.2} //# 15: compile-time error
+ = {1: 1} //# 16: compile-time error
+ = {{}} //# 17: compile-time error
+ = <Object>{} // Exact type. //# 18: compile-time error
;
Expect.isNull(s);
Set<Set<Object>> ss //
- = {{1: 1}} //# 14: compile-time error
- = {<int, int>{}} //# 15: compile-time error
- = {<int>{1: 1}} //# 16: compile-time error
- = const {ss} //# 17: compile-time error
+ = {{1: 1}} //# 19: compile-time error
+ = {<int, int>{}} //# 20: compile-time error
+ = {<int>{1: 1}} //# 21: compile-time error
+ = const {ss} //# 22: compile-time error
;
Expect.isNull(ss);
HashSet<int> hs //
- = {} // Exact type is LinkedHashSet //# 18: compile-time error
+ = {} // Exact type is LinkedHashSet //# 23: compile-time error
;
Expect.isNull(hs);
LinkedHashSet<int> lhs //
- = const {} // exact type is Set //# 19: compile-time error
+ = const {} // exact type is Set //# 24: compile-time error
;
Expect.isNull(lhs);
LinkedHashSet<LinkedHashSet<int>> lhs2 //
- = {const {}} // exact type LHS<Set>. // 20: compile-time error
+ = {const {}} // exact type LHS<Set>. //# 25: compile-time error
;
Expect.isNull(lhs2);
+
+ <T>(x) {
+ // Type constants are allowed, type variables are not.
+ var o //
+ = const {T} //# 26: compile-time error
+ = const {x} //# 27: compile-time error
+ ;
+ Expect.isNull(o);
+ }<int>(42);
}
diff --git a/tests/language_2/set_literals/set_literal_test.dart b/tests/language_2/set_literals/set_literal_test.dart
index cbcbfbd..03e9b0b 100644
--- a/tests/language_2/set_literals/set_literal_test.dart
+++ b/tests/language_2/set_literals/set_literal_test.dart
@@ -115,6 +115,16 @@
set = {{1}, {}}; // Set<Object>
Expect.type<Set<Object>>(x);
Expect.notType<Set<Set<Object>>>(x);
+
+ // Trailing comma.
+ Iterable<Object> i;
+ i = {1,};
+ Expect.type<Set<Object>>(i);
+ Expect.equals(1, i.length);
+
+ o = {1, 2, 3,};
+ Expect.type<Set<int>>(o);
+ Expect.equals(3, o.length);
}
class Equality {