Skip to content

New optional array access operator may fail on compilation with nil arrays #593

Discussion options

You must be logged in to vote

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 indexing arr[0].

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by antonmedv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #591 on March 04, 2024 22:16.