Skip to content

Commit

Permalink
Merge pull request #478 from jinko-core/forbid-generic-calls-on-non-g…
Browse files Browse the repository at this point in the history
…eneric-decls

Forbid generic calls on non generic decls
  • Loading branch information
CohenArthur authored Jan 16, 2022
2 parents 39b94c5 + e615794 commit c347b88
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/instruction/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions tests/ft/regression/462.jk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func id(x: int) -> int { x }

id[int](15); // error
5 changes: 5 additions & 0 deletions tests/ft/regression/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c347b88

Please sign in to comment.