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

Abstract generate @:impliciteCast instead of cast in some situation, cause different behavior on HL #11730

Open
yuxiaomao opened this issue Jul 19, 2024 · 0 comments

Comments

@yuxiaomao
Copy link
Contributor

yuxiaomao commented Jul 19, 2024

When working with -D hl-check, I saw the following situation generate @:implicitCast ([Meta:String] :implicitCast in dump). @:implicitCast is not parsed by HL, which cause a type mismatch on call to .split (Dynamic instead of String).
Simply separate the line in two will not remove such metadata, and the cast is done correctly.

I'm wondering if that's some abstract related issue? Because I didn't see other target parse @:implicitCast tag, and when checking with a larger codebase, @:implicitCast seems mostly generated with on a same type or with a Null<>.
Or maybe I'm missing something and it's better to fix it in HL?

class Test {
	public static function parse (json:String) {
		var rawData: DataRaw = haxe.Json.parse(json);
		var encoded = rawData.mappings.split(';'); // generate @:implicitCast instead of Cast before split
		trace(encoded);
	}

	static function main() {
		parse("{ \"mappings\" : \"some;thing\"}");
	}
}

abstract DataRaw(haxe.DynamicAccess<Any>) to haxe.DynamicAccess<Any> {
	public var mappings(get,never) : String;
	inline function get_mappings() : String
		return this.get('mappings');
}

Dump:

[Var encoded<12356>(VUsedByTyper):Array<String>]
	[Call:Array<String>]
		[Field:(delimiter : String) -> Array<String>]
			[Meta:String]
				:implicitCast
				[Cast:Dynamic]
					[Cast:Null<Any>]
						[Call:Dynamic]
							[Field:(o : Dynamic, field : String) -> Dynamic]
								[TypeExpr Reflect:Class<Reflect>]
								[FStatic:(o : Dynamic, field : String) -> Dynamic]
									Reflect
									field:(o : Dynamic, field : String) -> Dynamic
							[Cast:Dynamic<Any>] [Cast:haxe.DynamicAccess<Any>] [Local rawData(12337):DataRaw:DataRaw]
							[Const:String] "mappings"
			[FInstance:(delimiter : String) -> Array<String>]
				String
				split:(delimiter : String) -> Array<String>
		[Const:String] ";"
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