Skip to content

Commit

Permalink
[diagnostics] report null safety errors (#11729)
Browse files Browse the repository at this point in the history
* [diagnostics] report null safety errors

* [tests] update test for 7931
  • Loading branch information
kLabz authored Jul 19, 2024
1 parent 1a66e9b commit c4cc470
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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-};
}
}

0 comments on commit c4cc470

Please sign in to comment.