Skip to content

[js] Regression with null safety diagnostics #11904

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

Open
RblSb opened this issue Dec 29, 2024 · 2 comments · May be fixed by #12127
Open

[js] Regression with null safety diagnostics #11904

RblSb opened this issue Dec 29, 2024 · 2 comments · May be fixed by #12127
Assignees
Milestone

Comments

@RblSb
Copy link
Member

RblSb commented Dec 29, 2024

In nightly builds after file resave this error occurs: (no compilation errors). From vshaxe codebase, doesn't happen on interp.
Main.hx:

using StringTools;

@:nullSafety
class Main {
	static function main() {}

	static function extractReturnType(hint:String):Void {
		// Null safety: Cannot unify String with { charCodeAt : Int -> Int }
		for (i => code in hint) {}
	}
}
-cp src
-main Main
--js bin/main.js
@RblSb
Copy link
Member Author

RblSb commented Jan 4, 2025

Minimized example: StringTools.unsafeCodeAt("foo", 0).

This basically inlines return (cast s).charCodeAt(index):
https://github.com/HaxeFoundation/haxe/blob/development/std/StringTools.hx#L504

Not really a regression, happens since c4cc470

Unification errors here on TAbstract(Null, [TAbstract(Int, [])]) and TAbstract(Int, []) comparison (idk how is first type is maked here).
https://github.com/HaxeFoundation/haxe/blob/development/src/typing/nullSafety.ml#L233

Interestingly, this error does not happen if you copy unsafeCodeAt function to Main class and call it. But error will happen on file resave if you create separate class and call it like Tools.unsafeCodeAt("foo", 0), so it looks like server cache problem related to modules, and not a null safety cache thing.

@kLabz kLabz added this to the 5.0 preview 1 milestone Jan 21, 2025
@kLabz kLabz self-assigned this Feb 6, 2025
@kLabz
Copy link
Contributor

kLabz commented Feb 6, 2025

Yeah it's a hxb cache vs null safety issue; it goes away with -D disable-hxb-cache.

kLabz added a commit that referenced this issue Apr 1, 2025
kLabz added a commit that referenced this issue Apr 4, 2025
kLabz added a commit that referenced this issue Apr 4, 2025
kLabz added a commit that referenced this issue Apr 4, 2025
@kLabz kLabz linked a pull request Apr 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants