Skip to content

checker: fix nested if expr method call (fix #20976) - #21773

Merged
spytheman merged 1 commit into
vlang:masterfrom
yuyi98:fix_invalid_expr_call
Jul 1, 2024
Merged

spytheman merged 1 commit into
vlang:masterfrom
yuyi98:fix_invalid_expr_call

Conversation

@yuyi98

@yuyi98 yuyi98 commented Jul 1, 2024

Copy link
Copy Markdown
Member

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

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

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
@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