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 nested if expr method call (fix #20976) #21773

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jul 1, 2024

This PR fix nested if expr method call (fix #20976).

  • Fix nested if expr method call.
  • Add test.
fn main() {
	str_from_nested_exp1 := if true {
		if true { 'foo.bar' } else { 'foo.bar.baz' }.all_after('foo.')
	} else {
		'foo'
	}
	println(str_from_nested_exp1)
	assert str_from_nested_exp1 == 'bar'

	str_from_nested_exp2 := if true {
		(if true { 'foo.bar' } else { 'foo.bar.baz' }).all_after('foo.')
	} else {
		'foo'
	}
	println(str_from_nested_exp2)
	assert str_from_nested_exp2 == 'bar'

	str_from_nested_exp3 := if true {
		'foo'
	} else {
		if true { 'foo.bar' } else { 'foo.bar.baz' }.all_after('foo.')
	}
	println(str_from_nested_exp3)
	assert str_from_nested_exp3 == 'foo'

	str_from_nested_exp4 := if true {
		'foo'
	} else {
		(if true { 'foo.bar' } else { 'foo.bar.baz' }).all_after('foo.')
	}
	println(str_from_nested_exp4)
	assert str_from_nested_exp4 == 'foo'
}

PS D:\Test\v\tt1> v run .
bar
bar
foo
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 65ff74b into vlang:master Jul 1, 2024
76 checks passed
@yuyi98 yuyi98 deleted the fix_invalid_expr_call branch July 1, 2024 08:51
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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nested expression is treaded as invalid when trying to call a method on it
2 participants