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

[diagnostics] report null safety errors #11729

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/typing/nullSafety.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ let run (com:Common.context) (types:module_type list) =
timer();
match com.callbacks#get_null_safety_report with
| [] ->
List.iter (fun err -> com.error err.sm_msg err.sm_pos) (List.rev report.sr_errors)
List.iter (fun err -> Common.display_error com err.sm_msg err.sm_pos) (List.rev report.sr_errors)
| callbacks ->
let errors =
List.map (fun err -> (err.sm_msg, err.sm_pos)) report.sr_errors
Expand Down
18 changes: 18 additions & 0 deletions tests/server/src/cases/issues/Issue7931.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,26 @@ class Issue7931 extends TestCase {
runHaxe(args);
assertErrorMessage("Local variable s used without being initialized");
runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> {
Assert.equals(1, res.length);
Assert.equals(1, res[0].diagnostics.length);
Assert.equals("Local variable s used without being initialized", res[0].diagnostics[0].args);
Assert.same(transform.range(1,2), res[0].diagnostics[0].range);
});
}

function testNullSafety(_) {
var content = getTemplate("issues/Issue7931/Main1.hx");
var transform = Markers.parse(content);

vfs.putContent("Main.hx", transform.source);
var args = ["-main", "Main", "-js", "out.js", "--no-output"];
runHaxe(args);
assertErrorMessage("Null safety: Cannot assign nullable value here.");
runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> {
Assert.equals(1, res.length);
Assert.equals(1, res[0].diagnostics.length);
Assert.equals("Null safety: Cannot assign nullable value here.", res[0].diagnostics[0].args);
Assert.same(transform.range(1,2), res[0].diagnostics[0].range);
});
}
}
7 changes: 7 additions & 0 deletions tests/server/test/templates/issues/Issue7931/Main1.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@:nullSafety(StrictThreaded)
class Main {
static function main() {
var a = 1;
{-1-}a = null{-2-};
}
}
Loading