这是indexloc提供的服务,不要输入任何密码
Skip to content

The #optional_ok only works with procedures returning exactly two values #5924

@mikattack

Description

@mikattack

Context

Odin:    dev-2025-11-nightly:e5153a9
OS:      macOS Sequoia 15.7.1 (build 24G231, kernel 24.6.0)
CPU:     Apple M3 Pro
RAM:     36864 MiB
Backend: LLVM 20.1.8

Expected Behavior

Using the #optional_ok directive should work as long as the last returned value is a boolean.

Current Behavior

The compiler emits the following error with procedures emitting more two return values:

Error: A procedure type with the #optional_ok tag requires 2 return values, got 3
        foo :: proc(x: int) -> (a, b: int, ok: bool) #optional_ok {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Failure Information

In the Overview documentation, the #optional_ok directive is defined with:

Allows skipping the last return parameter, which needs to be a bool

This implies that number of return values should not matter, as long as last one is a boolean.

I am unable to find other documentation that defines the directive to apply when exactly two values are returned.

Steps to Reproduce

Attempt to compile a modified version of the #optional_ok directive's example on the Overview:

package example

import "core:fmt"

foo :: proc(x: int) -> (a, b: int, ok: bool) #optional_ok {
    return x + 1, x + 2, true
}

main :: proc() {
    ok: bool
    x, y: int
    for i in 0..<11 {
        x, y, ok = foo(i)
        fmt.printf("v: %v %v (%v)\n", x, y, ok)
    }
}

If the #optional_ok directive is removed, the program compiles and runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions