diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/tests/type | |
Diffstat (limited to 'tiger-compiler/tests/type')
37 files changed, 259 insertions, 0 deletions
diff --git a/tiger-compiler/tests/type/assign-loop-var.tig b/tiger-compiler/tests/type/assign-loop-var.tig new file mode 100644 index 0000000..e591256 --- /dev/null +++ b/tiger-compiler/tests/type/assign-loop-var.tig @@ -0,0 +1,3 @@ +/* error: index variable erroneously assigned to. */ +for i := 10 to 1 do + i := i - 1 diff --git a/tiger-compiler/tests/type/bad-main-args.tig b/tiger-compiler/tests/type/bad-main-args.tig new file mode 100644 index 0000000..50f3fde --- /dev/null +++ b/tiger-compiler/tests/type/bad-main-args.tig @@ -0,0 +1 @@ +function _main(argv: string) = () diff --git a/tiger-compiler/tests/type/bad-main-return.tig b/tiger-compiler/tests/type/bad-main-return.tig new file mode 100644 index 0000000..c9ccc81 --- /dev/null +++ b/tiger-compiler/tests/type/bad-main-return.tig @@ -0,0 +1 @@ +function _main(): int = 42 diff --git a/tiger-compiler/tests/type/box.tig b/tiger-compiler/tests/type/box.tig new file mode 100644 index 0000000..b811029 --- /dev/null +++ b/tiger-compiler/tests/type/box.tig @@ -0,0 +1,7 @@ +let + type box = { value : int } + type dup = { value : int, value : string } + var box := box { value = 51 } +in + box.head +end
\ No newline at end of file diff --git a/tiger-compiler/tests/type/compare_to_break.tig b/tiger-compiler/tests/type/compare_to_break.tig new file mode 100644 index 0000000..0fb2853 --- /dev/null +++ b/tiger-compiler/tests/type/compare_to_break.tig @@ -0,0 +1,3 @@ +/* Break cannot be used in comparaisons, especially at the left side */ +for i := 1 to 10 do + () = break diff --git a/tiger-compiler/tests/type/field-in-not-record.tig b/tiger-compiler/tests/type/field-in-not-record.tig new file mode 100644 index 0000000..227e80f --- /dev/null +++ b/tiger-compiler/tests/type/field-in-not-record.tig @@ -0,0 +1,7 @@ +/* error : variable "d" is not a record */ +let + var d := 0 +in + d.f +end + diff --git a/tiger-compiler/tests/type/field-twice-in-declaration.tig b/tiger-compiler/tests/type/field-twice-in-declaration.tig new file mode 100644 index 0000000..e7d38ee --- /dev/null +++ b/tiger-compiler/tests/type/field-twice-in-declaration.tig @@ -0,0 +1,8 @@ +/* Cannot declare the same record attribute more than once */ + +let + type dup = { value : int, value : string } + var box := dup { value = 51, value = "wow" } +in + box.value +end diff --git a/tiger-compiler/tests/type/field-twice-in-instantiation.tig b/tiger-compiler/tests/type/field-twice-in-instantiation.tig new file mode 100644 index 0000000..edccd6c --- /dev/null +++ b/tiger-compiler/tests/type/field-twice-in-instantiation.tig @@ -0,0 +1,8 @@ +/* Cannot set the same record attribute in instantiaition more than once */ + +let + type dup = { value : int, id: int } + var box := dup { value = 51, value = 15 } +in + box.value +end diff --git a/tiger-compiler/tests/type/funarg-type-mismatch.tig b/tiger-compiler/tests/type/funarg-type-mismatch.tig new file mode 100644 index 0000000..75c0a79 --- /dev/null +++ b/tiger-compiler/tests/type/funarg-type-mismatch.tig @@ -0,0 +1,6 @@ +/* error : formals and actuals have different types */ +let + function g(a : int , b : string) : int = a +in + g("one", "two") +end diff --git a/tiger-compiler/tests/type/lower_than_array.tig b/tiger-compiler/tests/type/lower_than_array.tig new file mode 100644 index 0000000..9e78236 --- /dev/null +++ b/tiger-compiler/tests/type/lower_than_array.tig @@ -0,0 +1,20 @@ +let + type arr = array of int + var arr1 := arr[5] of 0 + var arr2 := arr[5] of 1 +in + if (arr1 < arr2) then + print("lower"); + + if (arr1 <= arr2) then + print("lower or equal"); + + if (arr1 = arr2) then + print("equal"); + + if (arr1 >= arr2) then + print("higher or equal"); + + if (arr1 > arr2) then + print("higher") +end diff --git a/tiger-compiler/tests/type/lower_than_nil.tig b/tiger-compiler/tests/type/lower_than_nil.tig new file mode 100644 index 0000000..f53b0be --- /dev/null +++ b/tiger-compiler/tests/type/lower_than_nil.tig @@ -0,0 +1,20 @@ +let + type rec = { key : string, value : int } + var rec1 : rec := nil + var rec2 : rec := nil +in + if (rec1 < rec2) then + print("lower"); + + if (rec1 <= rec2) then + print("lower or equal"); + + if (rec1 = rec2) then + print("equal"); + + if (rec1 >= rec2) then + print("higher or equal"); + + if (rec1 > rec2) then + print("higher") +end diff --git a/tiger-compiler/tests/type/lower_than_record.tig b/tiger-compiler/tests/type/lower_than_record.tig new file mode 100644 index 0000000..883a56b --- /dev/null +++ b/tiger-compiler/tests/type/lower_than_record.tig @@ -0,0 +1,20 @@ +let + type rec = { key : string, value : int } + var rec1 := rec { key = "wow", value = 2 } + var rec2 := rec { key = "key", value = 3 } +in + if (rec1 < rec2) then + print("lower"); + + if (rec1 <= rec2) then + print("lower or equal"); + + if (rec1 = rec2) then + print("equal"); + + if (rec1 >= rec2) then + print("higher or equal"); + + if (rec1 > rec2) then + print("higher") +end diff --git a/tiger-compiler/tests/type/missing-arg.tig b/tiger-compiler/tests/type/missing-arg.tig new file mode 100644 index 0000000..979dcea --- /dev/null +++ b/tiger-compiler/tests/type/missing-arg.tig @@ -0,0 +1,6 @@ +/* error : formals are more then actuals */ +let + function g(a : int , b : string) : int = a +in + g("one") +end diff --git a/tiger-compiler/tests/type/nil-equals-nil.tig b/tiger-compiler/tests/type/nil-equals-nil.tig new file mode 100644 index 0000000..18732d1 --- /dev/null +++ b/tiger-compiler/tests/type/nil-equals-nil.tig @@ -0,0 +1,2 @@ +/* Cannot compare nil against itself */ +nil = nil diff --git a/tiger-compiler/tests/type/nil-string.tig b/tiger-compiler/tests/type/nil-string.tig new file mode 100644 index 0000000..c8d885e --- /dev/null +++ b/tiger-compiler/tests/type/nil-string.tig @@ -0,0 +1,7 @@ +/* error: string variable instantiated with nil */ + +let + var str: string := nil +in + print(str) +end diff --git a/tiger-compiler/tests/type/test09.tig b/tiger-compiler/tests/type/test09.tig new file mode 100644 index 0000000..64ff9f9 --- /dev/null +++ b/tiger-compiler/tests/type/test09.tig @@ -0,0 +1,3 @@ +/* error : types of then - else differ */ + +if (5>4) then 13 else " " diff --git a/tiger-compiler/tests/type/test10.tig b/tiger-compiler/tests/type/test10.tig new file mode 100644 index 0000000..2233079 --- /dev/null +++ b/tiger-compiler/tests/type/test10.tig @@ -0,0 +1,2 @@ +/* error : body of while not unit */ +while (10 > 5) do 5+6 diff --git a/tiger-compiler/tests/type/test11.tig b/tiger-compiler/tests/type/test11.tig new file mode 100644 index 0000000..6c84718 --- /dev/null +++ b/tiger-compiler/tests/type/test11.tig @@ -0,0 +1,3 @@ +/* error hi expr is not int. */ +for i := 10 to " " do + print("Tiger\n") diff --git a/tiger-compiler/tests/type/test13.tig b/tiger-compiler/tests/type/test13.tig new file mode 100644 index 0000000..29fcabc --- /dev/null +++ b/tiger-compiler/tests/type/test13.tig @@ -0,0 +1,3 @@ +/* error : comparison of incompatible types */ + +3 > "df" diff --git a/tiger-compiler/tests/type/test14.tig b/tiger-compiler/tests/type/test14.tig new file mode 100644 index 0000000..e1711a0 --- /dev/null +++ b/tiger-compiler/tests/type/test14.tig @@ -0,0 +1,13 @@ +/* error : compare rec with array */ + +let + + type arrtype = array of int + type rectype = {name : string, id : int} + + var rec := rectype {name="aname", id=0} + var arr := arrtype [3] of 0 + +in + if rec <> arr then 3 else 4 +end diff --git a/tiger-compiler/tests/type/test15.tig b/tiger-compiler/tests/type/test15.tig new file mode 100644 index 0000000..1af763e --- /dev/null +++ b/tiger-compiler/tests/type/test15.tig @@ -0,0 +1,3 @@ +/* error : if-then returns non unit */ + +if 20 then 3 diff --git a/tiger-compiler/tests/type/test21.tig b/tiger-compiler/tests/type/test21.tig new file mode 100644 index 0000000..5e466a3 --- /dev/null +++ b/tiger-compiler/tests/type/test21.tig @@ -0,0 +1,11 @@ +/* error : procedure returns value and procedure is used in arexpr */ +let + /* calculate n! */ + function nfactor(n : int) = + if n = 0 + then 1 + else n * nfactor(n-1) + +in + nfactor(10) +end diff --git a/tiger-compiler/tests/type/test22.tig b/tiger-compiler/tests/type/test22.tig new file mode 100644 index 0000000..899b586 --- /dev/null +++ b/tiger-compiler/tests/type/test22.tig @@ -0,0 +1,8 @@ +/* error : field not in record type */ + +let + type rectype = {name : string , id : int} + var rec1 := rectype {name="Name", id=0} +in + rec1.nam := "asd" +end diff --git a/tiger-compiler/tests/type/test23.tig b/tiger-compiler/tests/type/test23.tig new file mode 100644 index 0000000..2772067 --- /dev/null +++ b/tiger-compiler/tests/type/test23.tig @@ -0,0 +1,9 @@ +/* error : type mismatch */ + +let + type rectype = {name : string , id : int} + var rec1 := rectype {name="aname", id=0} +in + rec1.name := 3; + rec1.id := "" +end diff --git a/tiger-compiler/tests/type/test24.tig b/tiger-compiler/tests/type/test24.tig new file mode 100644 index 0000000..f9d0df5 --- /dev/null +++ b/tiger-compiler/tests/type/test24.tig @@ -0,0 +1,7 @@ +/* error : variable not array */ +let + var d :=0 +in + d[3] +end + diff --git a/tiger-compiler/tests/type/test26.tig b/tiger-compiler/tests/type/test26.tig new file mode 100644 index 0000000..bdd89fe --- /dev/null +++ b/tiger-compiler/tests/type/test26.tig @@ -0,0 +1,3 @@ +/* error : integer required */ + +3 + "var" diff --git a/tiger-compiler/tests/type/test28.tig b/tiger-compiler/tests/type/test28.tig new file mode 100644 index 0000000..9a52d8d --- /dev/null +++ b/tiger-compiler/tests/type/test28.tig @@ -0,0 +1,10 @@ +/* error : different record types */ + +let + type rectype1 = {name : string , id : int} + type rectype2 = {name : string , id : int} + + var rec1 : rectype1 := rectype2 {name="Name", id=0} +in + rec1 +end diff --git a/tiger-compiler/tests/type/test29.tig b/tiger-compiler/tests/type/test29.tig new file mode 100644 index 0000000..d47b966 --- /dev/null +++ b/tiger-compiler/tests/type/test29.tig @@ -0,0 +1,10 @@ +/* error : different array types */ + +let + type arrtype1 = array of int + type arrtype2 = array of int + + var arr1 : arrtype1 := arrtype2 [10] of 0 +in + arr1 +end diff --git a/tiger-compiler/tests/type/test31.tig b/tiger-compiler/tests/type/test31.tig new file mode 100644 index 0000000..1720610 --- /dev/null +++ b/tiger-compiler/tests/type/test31.tig @@ -0,0 +1,6 @@ +/* error : type constraint and init value differ */ +let + var a : int := " " +in + a +end diff --git a/tiger-compiler/tests/type/test32.tig b/tiger-compiler/tests/type/test32.tig new file mode 100644 index 0000000..cf9e854 --- /dev/null +++ b/tiger-compiler/tests/type/test32.tig @@ -0,0 +1,9 @@ +/* error : initializing exp and array type differ */ + +let + type arrayty = array of int + + var a := arrayty [10] of " " +in + 0 +end diff --git a/tiger-compiler/tests/type/test40.tig b/tiger-compiler/tests/type/test40.tig new file mode 100644 index 0000000..1765158 --- /dev/null +++ b/tiger-compiler/tests/type/test40.tig @@ -0,0 +1,7 @@ +/* error : procedure returns value */ +let + function g(a : int) = a +in + g(2) +end + diff --git a/tiger-compiler/tests/type/test43.tig b/tiger-compiler/tests/type/test43.tig new file mode 100644 index 0000000..d1dadc7 --- /dev/null +++ b/tiger-compiler/tests/type/test43.tig @@ -0,0 +1,7 @@ +/* error: initialize with unit and causing type mismatch in addition */ + +let + var a := () +in + a + 3 +end diff --git a/tiger-compiler/tests/type/too-many-args.tig b/tiger-compiler/tests/type/too-many-args.tig new file mode 100644 index 0000000..839575d --- /dev/null +++ b/tiger-compiler/tests/type/too-many-args.tig @@ -0,0 +1,6 @@ +/* error : formals are fewer then actuals */ +let + function g(a : int , b : string) : int = a +in + g(3,"one",5) +end diff --git a/tiger-compiler/tests/type/types-endless-recursion.tig b/tiger-compiler/tests/type/types-endless-recursion.tig new file mode 100644 index 0000000..ab51a94 --- /dev/null +++ b/tiger-compiler/tests/type/types-endless-recursion.tig @@ -0,0 +1,11 @@ +/* error : mutually recursive types that do not pass through record or array */ +let + +type a=c +type b=a +type c=d +type d=a + +in + "" +end diff --git a/tiger-compiler/tests/type/unconstrained-nil.tig b/tiger-compiler/tests/type/unconstrained-nil.tig new file mode 100644 index 0000000..eb0de8d --- /dev/null +++ b/tiger-compiler/tests/type/unconstrained-nil.tig @@ -0,0 +1,5 @@ +/* error : initializing nil expressions not constrained by record type */ +let var a := nil +in + 0 +end diff --git a/tiger-compiler/tests/type/wrong-print-invalid-type.tig b/tiger-compiler/tests/type/wrong-print-invalid-type.tig new file mode 100644 index 0000000..21fef12 --- /dev/null +++ b/tiger-compiler/tests/type/wrong-print-invalid-type.tig @@ -0,0 +1,2 @@ +/* Invalid argument type (int vs string) */ +print(1) diff --git a/tiger-compiler/tests/type/wrong-print-too-many-args.tig b/tiger-compiler/tests/type/wrong-print-too-many-args.tig new file mode 100644 index 0000000..c16a2f2 --- /dev/null +++ b/tiger-compiler/tests/type/wrong-print-too-many-args.tig @@ -0,0 +1,2 @@ +/* Too many arguments */ +print("a", "b", "c") |
