v icon indicating copy to clipboard operation
v copied to clipboard

C error. Compiler bug on type mismatch due to reference in if statements.

Open ttytm opened this issue 2 years ago • 0 comments

Describe the bug

const (
	some_runes       = [`a`, `b`, `c`]
	some_other_runes = [`c`, `b`, `a`]
)

fn main() {
	runes := if true { &some_runes } else { some_other_runes }
	println(runes)
}
C error. This should never happen.

This is a compiler bug, please report it...

With this comes a questions I couldn't answer myself in the docs. Which is how I even came to this error.

// does not work by default
// > error: use `array2 := array1.clone()` instead of `array2 := array1` (or use `unsafe`)
runes := some_runes
// this was my way to go then
runes := &some_runes
// works on the other hand without complaints
runes := if true { some_runes } else { some_other_runes }

Is the result of this condition cloned or automatically wrapped in unsafe or what's the reason that it works?

Expected Behavior

Regular type mismatch error.

Current Behavior

Compiler bug.

Reproduction Steps

Run code snippet above.

Possible Solution

No response

Additional Information/Context

No response

V version

0.3.3 6e1e406

Environment details (OS name and version, etc.)

linux arch

ttytm avatar Mar 16 '23 22:03 ttytm