Description
The current "Spread Collections" proposal does not allow using spread in a const list. This is necessary in cases where the object you are spreading could do unexpected computation, like:
class InfiniteSequence implements Iterable<int> {
const InfiniteSequence();
Iterator<int> get iterator {
return () sync* {
var i = 0;
while (true) yield i ++;
}();
}
}
const forever = [...InfiniteSequence()];
But in cases where the object being spread is an actual core library List object, the spread is safe. That's because it must be const (since it's inside a const context), and we have access to the actual value at compile time, not just its static type.
So we could say that you can spread inside a const list if and only if the spread object const-evaluates to a dart:core List.
Is this worth doing? Personally, I dislike adding yet more special cases for const shenanigans, and I rarely use const, so I'm not inclined. But if users feel it's important, I can see doing it.