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 auto str which expects ptr for ptr type #23553

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

felipensp
Copy link
Member

@felipensp felipensp commented Jan 22, 2025

Fix #23552

Copy link

Connected to Huly®: V_0.6-21981

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.

Very good work, but please add a test too, to prevent regressions.

Something like this works (with caveats):

module main

import net.html

fn main() {
	mut doc := html.parse('<body><div class="Box-footer"><div class="truncate">abc</div></div></body>')
	footer := doc.get_tags_by_class_name('Box-footer')[0]
	hrefs := footer.get_tag_by_class_name('Truncate')
	//dump(hrefs.str()) // cgen error
	println(hrefs) // ok
	// println(hrefs.str()) // runtime error, invalid memory access
	res := '${hrefs}'
	assert res == '&Option(&nil)'
}

@spytheman
Copy link
Member

What is interesting is that println(hrefs.str()) works, when <div class="truncate"> is changed to <div class="Truncate">, because then the output of the string method changes.

@felipensp felipensp marked this pull request as ready for review January 23, 2025 10:57
@felipensp
Copy link
Member Author

Very good work, but please add a test too, to prevent regressions.

Something like this works (with caveats):

module main

import net.html

fn main() {
	mut doc := html.parse('<body><div class="Box-footer"><div class="truncate">abc</div></div></body>')
	footer := doc.get_tags_by_class_name('Box-footer')[0]
	hrefs := footer.get_tag_by_class_name('Truncate')
	//dump(hrefs.str()) // cgen error
	println(hrefs) // ok
	// println(hrefs.str()) // runtime error, invalid memory access
	res := '${hrefs}'
	assert res == '&Option(&nil)'
}

Test added.

@spytheman spytheman merged commit 25f14d3 into vlang:master Jan 23, 2025
72 checks passed
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.

CGEN Error with HTML tags
2 participants