Skip to content

[nullsafety] Non-nullable check warnings #12231

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
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

RblSb
Copy link
Member

@RblSb RblSb commented May 10, 2025

Cannot undestand problem with warning diagnostics, need some help:
(nullsafety warnings will stay if there is nullsafety errors btw)

@:nullSafety
@:haxe.warning("-WRedundantNullCheck")
class Main {
	static function main() {
		new Main();
	}

	function new() {
		final foo = "1";
		// this warning doesn't react on WRedundantNullCheck
		// and also hides after vscode tab swap
		final v = foo ?? "0";

		final foo = 1;
		// no warning because of Null<Int> cast in operator
		// probably can be fixed with some @:nonNullable internal meta on expr
		final v = foo ?? 0;

		// working warning example
		final f:Int;
		function name():Void {
			f + 1;
		}
	}
}

Closes #7816

@kLabz
Copy link
Contributor

kLabz commented May 10, 2025

I will try to fix diagnostics vs cache early next week, that behavior is currently more or less expected.

Edit: was mostly about haxe.warning rules vs cached modules, but there are several things wrong in this PR that I'm working on fixing

@RblSb RblSb force-pushed the warn-nonnullable branch from aa636dc to a82fb7c Compare May 12, 2025 23:06
@kLabz
Copy link
Contributor

kLabz commented May 13, 2025

Reworked to make it work with type level @:haxe.warning rules:
kLabz@d9939f9

[Kinda] works with:

@:nullSafety
@:haxe.warning("+WRedundantNullCheck") // Notice the "+" instead of "-"
class Main {
	static function main() {}

	// TODO
	// @:haxe.warning("+WRedundantNullCheck")
	function new() {
		final foo = "1";
		// this warning does react to +WRedundantNullCheck
		// but still hides after vscode tab swap (warnings added in filter happen too late.. need to think about it)
		final v = foo ?? "0";
		ignore(v);
	}

	static function ignore<T>(v:T):Void {}
}

Field/expression level is doable but more annoying to handle. Can definitely be done, though.
Will look into that warnings in filters vs cache thing

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.

[nullsafety] errors or warnings for null checks on non-nullable types
2 participants