Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: fix closure in if guard (fix #19748) #19750

Merged
merged 1 commit into from
Nov 3, 2023

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Nov 3, 2023

This PR fix closure in if guard (fix #19748).

  • Fix closure in if guard.
  • Add test.
struct Foo {
	optional ?int
}

fn main() {
	f := Foo{45}
	mut ret := ''
	if v := f.optional {
		func := fn [v] () string {
			println(v)
			return '${v}'
		}
		ret = func()
	}
	assert ret == '45'
}

PS D:\Test\v\tt1> v run .
45

@spytheman spytheman merged commit ceb191d into vlang:master Nov 3, 2023
53 checks passed
@yuyi98 yuyi98 deleted the fix_closure_in_if_guard branch November 4, 2023 09:40
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.

Cannot use optional in closure
2 participants