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

cgen: fix reference variable str() method call (fix #19430) #21753

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jun 28, 2024

This PR fix reference variable str() method call (fix #19430).

  • Fix reference variable str() method call.
  • Add test.
@[heap]
struct Foo {
	bar string = 'bar'
	baz string = 'baz'
}

fn (foo Foo) str() string {
	return 'bar: ${foo.bar}, baz: ${foo.baz}'
}

fn main() {
	mut many_foos := []&Foo{len: 3, init: &Foo{}}
	println(many_foos.map(it.str()).join('\n'))
	println(many_foos)
	assert many_foos.map(it.str()) == ['&bar: bar, baz: baz', '&bar: bar, baz: baz',
		'&bar: bar, baz: baz']
}

PS D:\Test\v\tt1> v run .
&bar: bar, baz: baz
&bar: bar, baz: baz
&bar: bar, baz: baz
[&bar: bar, baz: baz, &bar: bar, baz: baz, &bar: bar, baz: baz]

@Delta456
Copy link
Member

I believe the OP links to the incorrect issue

@yuyi98
Copy link
Member Author

yuyi98 commented Jun 28, 2024

@Delta456 Thanks! My mistake.

@yuyi98 yuyi98 changed the title cgen: fix reference variable str() method call (fix #10430) cgen: fix reference variable str() method call (fix #19430) Jun 28, 2024
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 4a7c70c into vlang:master Jun 28, 2024
75 checks passed
@yuyi98 yuyi98 deleted the fix_ref_str branch June 28, 2024 14:07
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.

custom .str() function returns reference address instead of string
3 participants