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

HL/C generates invalid code for class members called "bool" #11293

Closed
MoritzBrueckner opened this issue Aug 11, 2023 · 0 comments
Closed

HL/C generates invalid code for class members called "bool" #11293

MoritzBrueckner opened this issue Aug 11, 2023 · 0 comments

Comments

@MoritzBrueckner
Copy link

If a class has a member variable called bool, Hashlink's C output fails to properly "escape" the name of the variable which causes syntax errors when compiling the C output:

class Main {
	static function main() {
		var a = new TShaderConstant(true);
		trace(a.bool);
	}
}

class TShaderConstant {
	public var bool: Bool;

	public function new(boolValue: Bool) {
		this.bool = boolValue;
	}
}
1>[...]\HL_BoolKeyword\out\_std\TShaderConstant.h(21,7): error C2632: 'bool' followed by 'bool' is illegal
1>[...]\HL_BoolKeyword\out\_std\TShaderConstant.h(21,11): error C2208: 'bool': no members defined using this type
1>[...]\HL_BoolKeyword\out\_std\Main.c(34,15): error C2059: syntax error: 'type'
1>[...]\HL_BoolKeyword\out\_std\Main.c(37,8): error C2275: 'String': expected an expression instead of a type
...

The generated code contains invalid lines like these:

struct _TShaderConstant {
	hl_type *$type;
	bool bool;
};
void TShaderConstant_new(TShaderConstant r0,bool r1) {
	r0->bool = r1;
	return;
}
TShaderConstant_new(r4,r3);
r3 = r4->bool;
r5 = hl_alloc_dynbool(r3);

Instead, bool should be renamed to _bool like other keywords. I think that in order to fix this, bool just needs to be added here. I don't have a build environment for Haxe at the moment, so I would appreciate if someone else could fix this. I attached a minimal example project below.

Windows 10 22H2 64 bit
Haxe 4.3.1 (stable release version)
Visual Studio 2022 (v17.7.0)

HL_BoolKeyword.zip
build.hxml is configured for Visual Studio 2019, so you might need to adjust this for your environment. Note that I opened the .sln with VS 2022 and let it upgrade the platform toolset to v143 (I don't have VS 2019 installed but HL doesn't have a VS 2022 config yet), but I'm confident that the issue is not related to the Visual Studio version. It also doesn't matter whether you compile for debug or release.

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

No branches or pull requests

1 participant