You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A proc with #optional_ok, when used with the iterator syntax sugar (for value in iterate(&it)), the boolean return value gets ignored, and the value gets iterated instead.
Which causes a compile error is the value is not iterable.
Example:
package bug
main :: proc() {
int_with_optional :: proc() -> (value: int, cond: bool) #optional_ok {return}
for value inint_with_optional() {
#assert(type_of(value) == int)
}
for {
value := int_with_optional() or_break#assert(type_of(value) == int)
}
int_without_optional :: proc() -> (value: int, cond: bool) {return}
for value inint_without_optional() {
#assert(type_of(value) == int)
}
for {
value := int_without_optional() or_break#assert(type_of(value) == int)
}
slice_with_optional :: proc() -> (value: []int, cond: bool) #optional_ok {return}
for value inslice_with_optional() {
#assert(type_of(value) == []int)
}
for {
value := slice_with_optional() or_break#assert(type_of(value) == []int)
}
slice_without_optional :: proc() -> (value: []int, cond: bool) {return}
for value inslice_without_optional() {
#assert(type_of(value) == []int)
}
for {
value := slice_without_optional() or_break#assert(type_of(value) == []int)
}
}
Errors:
bug/main.odin(6:15) Error: Cannot iterate over 'int_with_optional()' of type 'int'
for value in int_with_optional() {
^~~~~~~~~~~~~~~~~~^
bug/main.odin(7:19) Error: Undeclared name: value
#assert(type_of(value) == int)
^~~~^
bug/main.odin(7:29) Error: 'int' is not an expression but a type
#assert(type_of(value) == int)
^~^
bug/main.odin(7:3) Error: 'type_of(value) == int' is not a constant boolean
#assert(type_of(value) == int)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
bug/main.odin(29:3) Error: Compile time assertion: type_of(value) == []int
#assert(type_of(value) == []int)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
I would expect that the last return value will always be used as a condition for the for loop, with #optional_ok or without. And the returned value should only be iterated on if the procedure returns a single value.
The text was updated successfully, but these errors were encountered:
A proc with
#optional_ok
, when used with the iterator syntax sugar (for value in iterate(&it)
), the boolean return value gets ignored, and thevalue
gets iterated instead.Which causes a compile error is the
value
is not iterable.Example:
Errors:
Odin report:
Expected Behavior
I would expect that the last return value will always be used as a condition for the
for
loop, with#optional_ok
or without. And the returned value should only be iterated on if the procedure returns a single value.The text was updated successfully, but these errors were encountered: