Out-of-bounds access of array with or
block doesn't return the value of the or
block
#23451
Labels
Bug
This tag is applied to issues which reports bugs.
Option Type
Bugs/feature requests, that are related to `?Type`.
Status: Confirmed
This bug has been confirmed to be valid by a contributor.
Unit: cgen
Bugs/feature requests, that are related to the default C generating backend.
Unit: Compiler
Bugs/feature requests, that are related to the V compiler in general.
Describe the bug
With an array with optional values (as used in the standard lib,
db.pg
for example), trying to access an item out-of-bounds with anor
block, should return the value from theor
block. But that doesn't happen.Reproduction Steps
https://play.vlang.io/p/9326094f30
Expected Behavior
should print:
... Option('unknown')
Current Behavior
prints:
... Option(none)
Possible Solution
No response
Additional Information/Context
The out-of-bounds access logic with
or {}
blocks for arrays and maps seems to collide with the Option/Result logic. Genereally it should be possible to have a shortcut for accessing an element in an array and unwrapping the element, if it is an Optional. Otherwise, the element must be assigned to a new variable first and then unwrapped.V version
V 0.4.9 d2b30df
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: