Skip to content

cgen: fix option if expr with noreturn fn call (fix #22467)#22470

Merged
spytheman merged 2 commits intovlang:masterfrom
yuyi98:fix_if_expr_with_panic
Oct 10, 2024
Merged

cgen: fix option if expr with noreturn fn call (fix #22467)#22470
spytheman merged 2 commits intovlang:masterfrom
yuyi98:fix_if_expr_with_panic

Conversation

@yuyi98
Copy link
Copy Markdown
Member

@yuyi98 yuyi98 commented Oct 10, 2024

This PR fix option if expr with panic() call (fix #22467).

  • Fix option if expr with panic() call.
  • Add test.
fn main() {
	mut x := ?string(none)
	x = if true {
		''
	} else {
		panic('')
	}
	println(x)
}

PS D:\Test\v\tt1> v run .
Option('')

Comment thread vlib/v/gen/c/cgen.v Outdated
Copy link
Copy Markdown
Contributor

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman changed the title cgen: fix option if expr with panic() call (fix #22467) cgen: fix option if expr with noreturn fn call (fix #22467) Oct 10, 2024
@spytheman spytheman merged commit d3b380b into vlang:master Oct 10, 2024
@yuyi98 yuyi98 deleted the fix_if_expr_with_panic branch October 10, 2024 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cgen error for an if expression, with a panic() call in the else branch, assigned to a ?string variable

2 participants