v icon indicating copy to clipboard operation
v copied to clipboard

Initializing custom error type leads to a C error (but not if `Error` is simply embedded)

Open Wertzui123 opened this issue 2 years ago • 0 comments

Describe the bug

fn main() {
	dump(foo()!)
}

fn foo() !int {
	// do something
	if true {
		return 1
	}
	return my_error()
}

struct CustomError {
pub:
	msg  string
	code int
}

fn my_error() IError {
	return IError(CustomError{})
}

Expected Behavior

[.\\main.v:2] foo()!: 1

Current Behavior

error: '{' expected (got ";")
IError _t1 = I_main__CustomError_to_Interface_IError(((main__CustomError*)memdup(&(main__CustomError){.msg = (string){.str=(byteptr)"", .is_lit=1},.code = 0,}, sizeof(main__CustomError))));

Reproduction Steps

Compile the above code.

Possible Solution

No response

Additional Information/Context

Note that embedding Error instead of defining an msg and code field resolves the issue.

V version

V 0.3.3 7de3485

Environment details (OS name and version, etc.)

Windows 10

Wertzui123 avatar Mar 06 '23 14:03 Wertzui123