Skip to content

cgen: unable to pass a type alias instance directly as function paramΒ #27799

Description

@rilaaax

Describe the bug

When passing an instance of a type alias directly to a function, compiler generates incorrect C code.
If we assign it to a variable beforehand, there is no crash.

Reproduction Steps

type Bools = [4]bool

fn foo(_ Bools) {
}

fn main() {
	foo(Bools{})
}

Expected Behavior

success

Current Behavior

cc: /tmp/v_501/expected_expression.01KXJYB7YESN7AHHRKY67HS3X6.tmp.c:4315:12: error: expected expression
cc:  4315 |         main__foo({0});
cc:       |                   ^

Possible Solution

No response

Additional Information/Context

Same behavior when using a match expression to assign, excepted that writing an explicit return doesn't cause the crash.

type Bools = [4]bool

fn get(i int) Bools {
	return match i {
		0 {
			g := Bools{}
			g
		}
		else {
			Bools{} // fails
			// return Bools{} // works
		}
	}
}

fn main() {
	get(1)
}

V version

V 0.5.2 b07c40e

Environment details (OS name and version, etc.)

not relevant

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

    BugThis tag is applied to issues which reports bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions