Skip to content

cgen: or {} block containing a comptime $if/$else emits an undeclared result temp (_t3) #28022

Description

@medvednikov

V version: V 0.5.2 (master)
OS: Linux (reported via bugs.vlang.io)

Description

An or {} block whose body is a compile-time $if / $else emits an undeclared result temp: the branch bodies assign to and reference _t3, but _t3 is never declared, so the generated C fails with use of undeclared identifier '_t3'.

Reproduction

module main

fn g(i int) !int {
	return error('!')
}

x := g(1) or {
	$if !windows {
		panic(err)
	} $else {
		u32(0)
	}
}

Actual (generated C fails to compile)

error: use of undeclared identifier '_t3'
    _t3 = builtin___v_panic(builtin__IError_str(err));
    ...
    _t3;

The or {} result temp _t3 is used in the $if/$else branch bodies but never declared.

Expected

Compiles; the or {} block's result temp is declared for the comptime-$if body.

Reported via bugs.vlang.io (also seen inside a larger real program)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugs.vlang.ioReported via the bugs.vlang.io crash reporter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions