Start typechecking generics

This commit is contained in:
nora 2023-11-06 20:41:49 +01:00
parent bf73203182
commit 01d4238269
15 changed files with 248 additions and 19 deletions

View file

@ -0,0 +1,3 @@
function main() = (
let a: I32[I32] = 0;
);

View file

@ -0,0 +1,4 @@
error: type I32 does not take generic arguments
--> $DIR/generics_on_primitive.nil:2
2 | let a: I32[I32] = 0;
^^^

View file

@ -0,0 +1,8 @@
type A[T] = struct { a: T };
type B[T, U, V] = struct {
b: T,
d: V,
};
type C = ();
function test(a: A[I32], b: B[I32, Int, I32], c: C) = ;

View file

@ -0,0 +1,4 @@
error: `main` function not found
--> $DIR/structs.nil:1
1 | type A[T] = struct { a: T };
^

View file

@ -0,0 +1,23 @@
type A[T] = struct { a: T };
type B[T, U, V] = struct {
b: T,
d: V,
};
type C = ();
function test(
a1: A,
a2: A[],
a3: A[I32],
a4: A[I32, I32],
b1: B,
b2: B[],
b3: B[Int, Int],
b4: B[Int, I32, Int],
b5: B[Int, Int, Int, Int],
c1: C,
c2: C[],
c3: C[I32],
) = ;

View file

@ -0,0 +1,36 @@
error: expected 1 generic arguments, found 0
--> $DIR/wrong_amount.nil:9
9 | a1: A,
^
error: expected 1 generic arguments, found 0
--> $DIR/wrong_amount.nil:10
10 | a2: A[],
^
error: expected 1 generic arguments, found 2
--> $DIR/wrong_amount.nil:12
12 | a4: A[I32, I32],
^
error: expected 3 generic arguments, found 0
--> $DIR/wrong_amount.nil:14
14 | b1: B,
^
error: expected 3 generic arguments, found 0
--> $DIR/wrong_amount.nil:15
15 | b2: B[],
^
error: expected 3 generic arguments, found 2
--> $DIR/wrong_amount.nil:16
16 | b3: B[Int, Int],
^
error: expected 3 generic arguments, found 4
--> $DIR/wrong_amount.nil:18
18 | b5: B[Int, Int, Int, Int],
^
error: type () does not take generic arguments
--> $DIR/wrong_amount.nil:22
22 | c3: C[I32],
^
error: `main` function not found
--> $DIR/wrong_amount.nil:1
1 | type A[T] = struct { a: T };
^