Skip to content
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
34 changes: 24 additions & 10 deletions test/test_call_diagnostics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,43 @@ let line_of (e : Typecheck.type_error) =
| Typecheck.Located (_, s) -> s.Span.start_pos.line
| _ -> Alcotest.failf "error has no location: %s" (Typecheck.format_type_error e)

(* Since #863 a statement `if`/`match` ends at its closing brace, so the #644
shape (`if c { .. }` then `(u, 2)` on the next line, or the same line)
type-checks. A statement whose head is a parenthesised `if`/`match` that
is then called still reaches [StatementContinued]. *)
let continued_if_is_named_and_located () =
let e = expect_error
"pub fn f(t: Int) -> (Int, Int) {\n\
\ let mut u = t;\n\
\ if u > 0 { u = 1; }\n\
\ (u, 2)\n\
"pub fn f(c: Bool) -> Int {\n\
\ (if c { () } else { () })(3);\n\
\ 0\n\
}\n" in
Alcotest.(check int) "line of the if" 3 (line_of e);
Alcotest.(check int) "line of the if" 2 (line_of e);
match e with
| Typecheck.Located (Typecheck.StatementContinued { kind = "if"; _ }, _) -> ()
| _ -> Alcotest.failf "expected StatementContinued if, got %s" (Typecheck.format_type_error e)

let continued_match_is_named_and_located () =
let e = expect_error
"pub fn f(t: Int) -> (Int, Int) {\n\
\ let mut u = t;\n\
\ match u { 0 => { u = 1; }, _ => {} }\n\
\ (u, 2)\n\
"pub fn f(n: Int) -> Int {\n\
\ (match n { 0 => (), _ => () })(3);\n\
\ 0\n\
}\n" in
Alcotest.(check int) "line of the match" 3 (line_of e);
Alcotest.(check int) "line of the match" 2 (line_of e);
match e with
| Typecheck.Located (Typecheck.StatementContinued { kind = "match"; _ }, _) -> ()
| _ -> Alcotest.failf "expected StatementContinued match, got %s" (Typecheck.format_type_error e)

(* #863: the old #644 shapes are no longer calls. *)
let statement_if_then_tuple_typechecks () =
List.iter (fun src ->
match typecheck src with
| Ok () -> ()
| Error e -> Alcotest.failf "#863: a statement if/match ends at its brace: %s"
(Typecheck.format_type_error e))
[ "pub fn f(t: Int) -> (Int, Int) {\n let mut u = t;\n if u > 0 { u = 1; }\n (u, 2)\n}\n";
"pub fn f(t: Int) -> (Int, Int) {\n let mut u = t;\n if u > 0 { u = 1; } (u, 2)\n}\n";
"pub fn f(t: Int) -> (Int, Int) {\n let mut u = t;\n match u { 0 => { u = 1; }, _ => {} }\n (u, 2)\n}\n" ]

(* A value-position `if` that is not Unit was not a continued statement:
plain E0104, located, with no `;` advice (CodeRabbit review on #862). *)
let value_position_if_keeps_not_a_function () =
Expand Down Expand Up @@ -127,6 +140,7 @@ let char_to_string_rejects_a_string () =

let tests = [
Alcotest.test_case "continued if: named and located" `Quick continued_if_is_named_and_located;
Alcotest.test_case "#863: statement if/match then tuple type-checks" `Quick statement_if_then_tuple_typechecks;
Alcotest.test_case "continued match: named and located" `Quick continued_match_is_named_and_located;
Alcotest.test_case "the ; remedy type-checks" `Quick the_documented_remedy_typechecks;
Alcotest.test_case "value-position if keeps NotAFunction" `Quick value_position_if_keeps_not_a_function;
Expand Down
2 changes: 1 addition & 1 deletion test/test_interp_eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ let cli_eval_forward_and_mutual () =
check "eval: forward reference" "eval" "fwd.affine" [ "3" ];
check "eval: mutual recursion" "eval" "mutual.affine" [ "even" ];
check "eval --json: mutual recursion" "eval --json" "mutual.affine"
[ "even"; {|{"version":1,"diagnostics":[],"success":true}|} ]
[ "even"; {|{"diagnostics":[],"success":true,"version":1}|} ]

let tests = [
Alcotest.test_case "self-recursion" `Quick self_recursion;
Expand Down
26 changes: 14 additions & 12 deletions test/test_jcs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
the BMP, number spelling at both ES6 switch points, and control-character
escaping. See docs/reference/JSON-AND-YAML.adoc. *)

let open Yojson.Basic
open Affinescript

(* U+20AC, U+00E9, U+1F600, U+E000, U+FFFD *)
let euro = "\226\130\172"
Expand All @@ -35,21 +35,21 @@ let canonical_inputs : (string * Yojson.Basic.t * string) list = [
; ("string", `String (euro ^ "$\015\nA'B\"\\\\\"/"))
]
, "{\"literals\":[null,true,false],\"numbers\":[333333333.3333333,1e+30,4.5,0.002,1e-27],\"string\":\"\226\130\172$\\u000f\\nA'B\\\"\\\\\\\\\\\"/\"}" )
( "keys sort by UTF-16 code units, not by insertion order"
; ( "keys sort by UTF-16 code units, not by insertion order"
, `Assoc [ ("b", `Int 1); ("a", `Int 2); ("A", `Int 3); ("aa", `Int 4); ("", `Int 5) ]
, "{\"\":5,\"A\":3,\"a\":2,\"aa\":4,\"b\":1}" )
( "nested objects and non-ASCII keys pass through verbatim"
; ( "nested objects and non-ASCII keys pass through verbatim"
, `Assoc
[ ("z", `List [ `Int 1; `Int 2; `Assoc [ ("y", `Null) ] ])
; (eacute, `Int 1)
; ("e", `Int 2)
]
, "{\"e\":2,\"z\":[1,2,{\"y\":null}],\"\195\169\":1}" )
( "an astral key precedes U+E000 (the case UTF-8 byte order gets wrong)"
; ( "an astral key precedes U+E000 (the case UTF-8 byte order gets wrong)"
, `Assoc
[ ("astral", `Int 1); (emoji, `Int 2); (replacement, `Int 3); (pua, `Int 4) ]
, "{\"astral\":1,\"\240\159\152\128\":2,\"\238\128\128\":4,\"\239\191\189\":3}" )
( "ES6 number placement: 1e21 vs 1e20, 1e-7 vs 1e-6, subnormals, -0"
; ( "ES6 number placement: 1e21 vs 1e20, 1e-7 vs 1e-6, subnormals, -0"
, `List
[ `Int 0
; `Float (-0.)
Expand All @@ -64,7 +64,7 @@ let canonical_inputs : (string * Yojson.Basic.t * string) list = [
; `Float 0.1
]
, "[0,0,1e+21,100000000000000000000,1e-7,0.000001,5e-324,1.7976931348623157e+308,123456789012345680000,-2.5,0.1]" )
( "nested reshaping keeps canonical order at every level"
; ( "nested reshaping keeps canonical order at every level"
, `Assoc
[ ( "nested",
`Assoc
Expand Down Expand Up @@ -95,9 +95,11 @@ let test_rejected (name, input) () =
| Error _ -> ()

let tests =
[ ( "canonical serialisation",
List.map (fun v -> Alcotest.test_case (let n, _, _ = v in n) `Quick (test_canonical v))
canonical_inputs )
; ( "I-JSON rejections",
List.map (fun v -> Alcotest.test_case (let n, _ = v in n) `Quick (test_rejected v)) rejected )
]
List.map
(fun ((name, _, _) as v) ->
Alcotest.test_case ("canonical: " ^ name) `Quick (test_canonical v))
canonical_inputs
@ List.map
(fun ((name, _) as v) ->
Alcotest.test_case ("rejected: " ^ name) `Quick (test_rejected v))
rejected
2 changes: 1 addition & 1 deletion tools/soundness-anchors.sha256
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# Regenerate: tools/check-soundness-ledger.sh --reseal
# Format: <sha256> <kind:locator>. FIXTURE = file hash; TEST = the
# test's function-body hash; SUITE = whole-file hash.
02aa1c6d9d1f8f141c1d7c5701ad08986a1536eadd02596a7715f0c2e7c65877 suite:test/test_interp_eval.ml
09f299eaf7e9a0d912db441f346438e31ea7157f6f730ab1b6d78ef6d22a76a1 test:test_801_planted_collision_refused
0d3623cf36a67860106d64bb32d30633978bb426d4ddd77ecc2bf6e48e1b7263 fixture:test/e2e/fixtures/borrow_callee_returned_borrow_uam.affine
20e73d88738c8fd075f81a36803554f92fa4ee53f71e33fa6759eae07c6e70f4 suite:test/test_intrinsic_shadow.ml
2bbd1b989fd0097530eede3e5230258e0e1092271a23ff7dff20cca65c0e612e suite:test/test_wasm_call_resolution.ml
2dfe36a21983a7dfb7ffa1157f7ddec9865a531a92682976b8fd677e4825e78d test:test_801_impl_methods_refused
3cb9faf269f704f02ce9f595affde2ddb73f66dd31964ec294182aa50e46afa7 suite:test/test_interp_eval.ml
45eb0f3aa5f643afbd003248998dd5a046688418647b491e0f2d4bb55fcbd0f2 test:test_wasm_heap_exhaustion_traps
49031b601e4e9f165b9539ce59be7aefe4917fb2317841c2678b5cfc0a2f23d6 suite:test/test_mut_param_848.ml
546939eaa3c64c82edd23da0a3ba7f74bcf7378cfe1e426132dd1a9f8fd46050 test:test_801_transitive_public_and_const
Expand Down
Loading