Skip to content

Commit

Permalink
Merge pull request #458 from jinko-core/typecheck-generated-fn
Browse files Browse the repository at this point in the history
Typecheck generated function
  • Loading branch information
CohenArthur authored Dec 28, 2021
2 parents cffa554 + f9ce95c commit 660c5a6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/ft/generics/generic_fns.jk
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@
func returns_generic[T]() -> T { true }

func id[T](value: T) -> T { value }

func call_bark_method[T](instance: T) {
instance.bark()
}

func animal_full_suite[A](animal: A) {
animal.bark();
animal.eat();
animal.scream();
animal.run();
animal.swim();
animal.fly();
}
15 changes: 15 additions & 0 deletions tests/ft/generics/generics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ tests:
args:
- "tests/ft/generics/valid_call_generic_twice.jk"
exit_code: 0
- name: "Valid use of ducktyping"
binary: "target/debug/jinko"
args:
- "tests/ft/generics/valid_ducktyping.jk"
exit_code: 0
- name: "Valid multi-use of ducktyping"
binary: "target/debug/jinko"
args:
- "tests/ft/generics/valid_multiple_ducktyping.jk"
exit_code: 0
- name: "Invalid use of ducktyping"
binary: "target/debug/jinko"
args:
- "tests/ft/generics/invalid_ducktyping.jk"
exit_code: 1
14 changes: 14 additions & 0 deletions tests/ft/generics/invalid_ducktyping.jk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
incl generic_fns

func bark(dog: int) {
println("I'm an integer wtf")
}

type Cat;

func meow(cat: Cat) {
// It's a silent cat
}

garfield = Cat;
call_bark_method[Cat](garfield);
11 changes: 11 additions & 0 deletions tests/ft/generics/valid_ducktyping.jk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
incl generic_fns

type Dog;

func bark(dog: Dog) {
println("Hey!")
}

// Create an instance of Dog
rex = Dog;
call_bark_method[Dog](rex);
13 changes: 13 additions & 0 deletions tests/ft/generics/valid_multiple_ducktyping.jk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
incl generic_fns;

type Griffin;

func bark[Griffin](g: Griffin) {}
func eat[Griffin](g: Griffin) {}
func scream[Griffin](g: Griffin) {}
func run[Griffin](g: Griffin) {}
func swim[Griffin](g: Griffin) {}
func fly[Griffin](g: Griffin) {}

griffin_instance = Griffin;
animal_full_suite[Griffin](griffin_instance);

0 comments on commit 660c5a6

Please sign in to comment.