Skip to content

cgen: fix auto str which expects ptr for ptr type#23553

Merged
spytheman merged 2 commits into
vlang:masterfrom
felipensp:fix_auto_str_ptr
Jan 23, 2025
Merged

cgen: fix auto str which expects ptr for ptr type#23553
spytheman merged 2 commits into
vlang:masterfrom
felipensp:fix_auto_str_ptr

Conversation

@felipensp

@felipensp felipensp commented Jan 22, 2025

Copy link
Copy Markdown
Member

Fix #23552

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-21981

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

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
Copy Markdown
Contributor

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
Copy Markdown
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
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