From 9a32556b4d1e2170cd49bd8ff64217c5af530390 Mon Sep 17 00:00:00 2001 From: CohenArthur Date: Sun, 16 Jan 2022 20:33:47 +0100 Subject: [PATCH 1/2] ft: Add regression test case for #462 --- tests/ft/regression/462.jk | 3 +++ tests/ft/regression/regression.yml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 tests/ft/regression/462.jk diff --git a/tests/ft/regression/462.jk b/tests/ft/regression/462.jk new file mode 100644 index 00000000..4e959446 --- /dev/null +++ b/tests/ft/regression/462.jk @@ -0,0 +1,3 @@ +func id(x: int) -> int { x } + +id[int](15); // error diff --git a/tests/ft/regression/regression.yml b/tests/ft/regression/regression.yml index 3119494c..1277ee6a 100644 --- a/tests/ft/regression/regression.yml +++ b/tests/ft/regression/regression.yml @@ -56,3 +56,8 @@ tests: - "tests/ft/regression/468.jk" stdout: "in test!\n" exit_code: 0 + - name: "Forbid calling non-generic fn with generic arguments #462" + binary: "target/debug/jinko" + args: + - "tests/ft/regression/462.jk" + exit_code: 1 From e615794a5f7120cc8dcccdd033d2c87b9fde5942 Mon Sep 17 00:00:00 2001 From: CohenArthur Date: Sun, 16 Jan 2022 20:33:59 +0100 Subject: [PATCH 2/2] function_call: Error out if call contains generics despite declaration not having any --- src/instruction/function_call.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/instruction/function_call.rs b/src/instruction/function_call.rs index d5e38e04..eb79cc20 100644 --- a/src/instruction/function_call.rs +++ b/src/instruction/function_call.rs @@ -308,6 +308,15 @@ impl Generic for FunctionCall { None => return, }; + if !self.generics.is_empty() && dec.generics().is_empty() { + // FIXME: Format generic list in error too + ctx.error(Error::new(ErrKind::Generics).with_msg(format!( + "calling non-generic function with generic arguments: `{}`", + self.name() + ))); + return; + } + let type_map = match GenericMap::create(dec.generics(), &self.generics, &mut ctx.typechecker) { Err(e) => {