From 537c924a68a3dc3e1876801f7ec536d951841f2e Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:28:00 +0100 Subject: [PATCH] fix some bugs --- src/typeck.ts | 1 + std/list.nil | 21 +++++++++++++++++++++ std/std.mod.nil | 1 + test.nil | 15 ++++----------- ui-tests/functions/missing_args.nil | 5 +++++ ui-tests/functions/missing_args.stderr | 4 ++++ ui-tests/type/generics/codegen.nil | 11 +++++++++++ 7 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 std/list.nil create mode 100644 ui-tests/functions/missing_args.nil create mode 100644 ui-tests/functions/missing_args.stderr create mode 100644 ui-tests/type/generics/codegen.nil diff --git a/src/typeck.ts b/src/typeck.ts index 2bf9176..325cf35 100644 --- a/src/typeck.ts +++ b/src/typeck.ts @@ -1328,6 +1328,7 @@ function checkCall( expr.span, ), ); + return; } fcx.infcx.assign(param, args[i].ty, args[i].span); diff --git a/std/list.nil b/std/list.nil new file mode 100644 index 0000000..d7e0184 --- /dev/null +++ b/std/list.nil @@ -0,0 +1,21 @@ +type List[T] = struct { + ptr: Int, + len: Int, + cap: Int, +}; + +function new(): List[Int] = ( + List { ptr: 0, len: 0, cap: 0 } +); + +function push(list: List[Int], elem: Int) = ( + growIfNeeded(list, 1); +); + +// PRIVATE: + +function growIfNeeded(list: List[Int], elems: Int) = ( + if (list.len + elems) < list.cap then ( + let newMemory = std.rt.alloc.allocateItem(0_I32, 0_I32); + ); +); diff --git a/std/std.mod.nil b/std/std.mod.nil index a7980f1..1941fc2 100644 --- a/std/std.mod.nil +++ b/std/std.mod.nil @@ -1,4 +1,5 @@ mod rt; +mod list; function printlnI32(x: I32) = ( printI32(x); diff --git a/test.nil b/test.nil index 6d5e163..7b7c8d8 100644 --- a/test.nil +++ b/test.nil @@ -1,11 +1,4 @@ -//@check-pass -type A[T] = struct { a: T }; -type B[T, U, V] = struct { - b: T, - d: V, -}; -type C = (); - -function main() = ; - -function test(a: A[I32], b: B[I32, Int, I32], c: C) = ; +function main() = ( + let list = std.list.new(); + std.list.push(list, 0); +); \ No newline at end of file diff --git a/ui-tests/functions/missing_args.nil b/ui-tests/functions/missing_args.nil new file mode 100644 index 0000000..d247851 --- /dev/null +++ b/ui-tests/functions/missing_args.nil @@ -0,0 +1,5 @@ +function main() = ( + x(); +); + +function x(a: Int) = ; \ No newline at end of file diff --git a/ui-tests/functions/missing_args.stderr b/ui-tests/functions/missing_args.stderr new file mode 100644 index 0000000..cbee1c7 --- /dev/null +++ b/ui-tests/functions/missing_args.stderr @@ -0,0 +1,4 @@ +error: missing argument of type Int + --> $DIR/missing_args.nil:2 +2 | x(); + ^ diff --git a/ui-tests/type/generics/codegen.nil b/ui-tests/type/generics/codegen.nil new file mode 100644 index 0000000..6d5e163 --- /dev/null +++ b/ui-tests/type/generics/codegen.nil @@ -0,0 +1,11 @@ +//@check-pass +type A[T] = struct { a: T }; +type B[T, U, V] = struct { + b: T, + d: V, +}; +type C = (); + +function main() = ; + +function test(a: A[I32], b: B[I32, Int, I32], c: C) = ;