aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChimrod <>2024-12-25 20:52:03 +0100
committerChimrod <>2024-12-25 21:42:18 +0100
commit9b831d2a2401c771cf43a37b27c8909d6b9c9ba8 (patch)
treea0d4ec0f1821731cb1e23363806f0cdd420e213b
parent706e2132e443ed422912264f0401ee607d1d2ef5 (diff)
Fixed a bug in the analysis of the min arguments
-rw-r--r--lib/checks/get_type.ml5
-rw-r--r--test/get_type.ml25
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/checks/get_type.ml b/lib/checks/get_type.ml
index a73eb1b..04bf780 100644
--- a/lib/checks/get_type.ml
+++ b/lib/checks/get_type.ml
@@ -110,7 +110,10 @@ let function_ : S.pos -> T.function_ -> t list -> t =
| Len -> Raw Integer
| Loc -> Variable Bool
| Max | Max' | Min | Min' -> (
- try List.hd params with Failure _ -> Raw Bool)
+ match params with
+ | [] -> Raw Bool
+ | Raw String :: [] | Variable String :: [] -> Variable NumericString
+ | hd :: _ -> hd)
| Mid | Mid' -> Variable String
| Msecscount -> Raw Integer
| Rand -> Raw Integer
diff --git a/test/get_type.ml b/test/get_type.ml
index 40b3151..55f087e 100644
--- a/test/get_type.ml
+++ b/test/get_type.ml
@@ -66,6 +66,30 @@ let literal_4 () =
let msg = "" in
Alcotest.(check' type_of ~msg ~expected ~actual)
+let min () =
+ let actual = Get_type.function_ _position T.Min [] in
+ let expected = Get_type.(Raw Bool) in
+ let msg = "The function min without argument return a default value" in
+ Alcotest.(check' type_of ~msg ~expected ~actual);
+
+ let actual =
+ Get_type.function_ _position T.Min [ Get_type.literal _position [] ]
+ in
+ let expected = Get_type.(Variable NumericString) in
+ let msg =
+ "The function min with a literal will take the literal as the name of an \
+ array"
+ in
+ Alcotest.(check' type_of ~msg ~expected ~actual);
+
+ let actual =
+ Get_type.function_ _position T.Min
+ [ Get_type.integer _position ""; Get_type.integer _position "" ]
+ in
+ let expected = Get_type.(Raw Integer) in
+ let msg = "With two or more arguments, return the type of the first one" in
+ Alcotest.(check' type_of ~msg ~expected ~actual)
+
let test =
( "Type expression",
[
@@ -76,4 +100,5 @@ let test =
Alcotest.test_case "1<<int>>" `Quick literal_2;
Alcotest.test_case "b<<int>>" `Quick literal_3;
Alcotest.test_case "<<$int>>" `Quick literal_4;
+ Alcotest.test_case "min" `Quick min;
] )