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 result call or_block with multi-statements (fix #21504) #21717

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jun 23, 2024

This PR fix result call or_block with multi-statements (fix #21504).

  • Fix result call or_block with multi-statements.
  • Add test.
fn str_ret_fn(str string) string {
	return str
}

fn foo(str string) !string {
	if str.contains('foo') {
		return str
	}
	return error('error')
}

fn main() {
	var := foo('bar') or {
		foo_var := str_ret_fn('foo')
		if foo_var == 'foo' {
			foo(foo_var) or {
				eprintln(err)
				exit(1)
			}
		} else {
			eprintln(err)
			exit(1)
		}
	}

	println(var)
	assert var == 'foo'
}

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

Copy link
Member

@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 merged commit f5c87a1 into vlang:master Jun 24, 2024
76 checks passed
@spytheman spytheman added the Unit: Checker Bugs/feature requests, that are related to the type checker. label Jun 24, 2024
@yuyi98 yuyi98 deleted the fix_fn_result_value branch June 24, 2024 09:27
raw-bin pushed a commit to raw-bin/v that referenced this pull request Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Storing a function result value in a variable does not work as expected in an or block
2 participants