New optional array access operator may fail on compilation with nil arrays #593
-
If the compiler knows a variable is nil, the (very cool!) ?.[] operator fails.
The error is: This one, however, succeed:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Compiler don't know the resulting type of If type(x) == type(y), compiler assumes return type of whole expression And in your example: type(nil) != type([1]), so compiler assigns |
Beta Was this translation helpful? Give feedback.
Compiler don't know the resulting type of
cond ? x : y
expression on compilation step.If type(x) == type(y), compiler assumes return type of whole expression
cond ? x : y
is type(x).If type(x) != type(y), compiler assumes retutn type of whole expression
cond ? x : y
is any.And in your example: type(nil) != type([1]), so compiler assigns
arr
any type. And any may support indexingarr[0]
.