Let c1[c2] be a compile time constant expression. #21625
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-duplicate
Closed in favor of an existing report
type-enhancement
A request for a change that isn't a bug
If
c1
is a compile-time constant List, Map or String, andc2
is a compile-time constant too, we could allowc1[c2]
as a compile-time constant expression.It will throw if
c1
is a List or String andc2
is not an integer or it is < 0 or >=c1.length
. The result is either the element at indexc2
, ifc1
is a List, or the substring of length 1 at indexc2
whenc1
is a String.If
c1
is a Map, any key is allowed, andc1[c2]
evaluates tonull
ifc2
isn't a key in the map - since the keys of a constant map must not overrideoperator==
, the lookup is a safe constant operation.The text was updated successfully, but these errors were encountered: