Skip to content

cgen: unwrap and c-mangle field selectors in or blocks#17495

Merged
spytheman merged 2 commits intovlang:masterfrom
edam:pr-cname-selector-or
Mar 4, 2023
Merged

cgen: unwrap and c-mangle field selectors in or blocks#17495
spytheman merged 2 commits intovlang:masterfrom
edam:pr-cname-selector-or

Conversation

@edam
Copy link
Copy Markdown
Member

@edam edam commented Mar 3, 2023

This PR fixes the case where C keywords are not correctly mangled in field selectors with or blocks.

The following code otherwise generates invalid C:

struct Foo {
    long ?string // field is C keyword
}
fn main() {
    foo := Foo{''}
    println(foo.long or {''}) // generates invalid code
}

The following C code is generated:

VV_LOCAL_SYMBOL void main__main(void) {
	_option_string _t1;
	_option_ok(&(string[]) { _SLIT("") }, (_option*)(&_t1), sizeof(string));
	main__Foo f = ((main__Foo){._v_long = _t1,});
	_option_string _t2 = f.long;  // ERROR: field name is keyword
	if (_t2.state != 0) {
		IError err = _t2.err;
		*(string*) _t2.data = _SLIT("");
	}
	println( (*(string*)_t2.data));
}

There is no open ticket for this issue (that I'm aware of).

PR includes test.

@spytheman
Copy link
Copy Markdown
Contributor

The CI failure is unrelated (it is a timed out slow running github job).

Copy link
Copy Markdown
Contributor

@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 3f8821b into vlang:master Mar 4, 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.

3 participants