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

ast, cgen: fix as cast with call expr (fix #19453) #19462

Merged
merged 3 commits into from
Sep 29, 2023

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 28, 2023

This PR fix as cast with call expr (fix #19453).

  • Fix as cast with call expr.
  • Add test.
type Numbers = int | string

struct Values {
	value Numbers
}

struct Wrapper {
	element []Values
mut:
	index int
}

fn (mut instance Wrapper) get() Values {
	println('Gets called')
	return instance.element[0]
}

fn main() {
	mut wrapper := Wrapper{
		element: [
			Values{
				value: 1
			},
			Values{
				value: '2'
			},
		]
	}
	println(wrapper.get().value as int)
}

PS D:\Test\v\tt1> v run .
Gets called
1

@spytheman
Copy link
Member

The linux and macos failures are fixed on master (just rebase), the windows one may need local fixes though.

@yuyi98
Copy link
Member Author

yuyi98 commented Sep 28, 2023

OK, I'll try to fix it.

cmd/tools/vtest-self.v Outdated Show resolved Hide resolved
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.

Good work.

@spytheman spytheman merged commit 74997fd into vlang:master Sep 29, 2023
@yuyi98 yuyi98 deleted the fix_as_cast_with_call_expr branch September 29, 2023 09:51
Wertzui123 pushed a commit to Wertzui123/v that referenced this pull request Oct 8, 2023
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.

Method called twice when mixed with "as"operator
2 participants