-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow explicit application of type arguments (#821)
Closes #770
- Loading branch information
Showing
22 changed files
with
396 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Error: Type mismatch (at $FILE:17:13) | ||
| | ||
15 | @guppy(module) | ||
16 | def main(x: float) -> None: | ||
17 | foo[int](x) | ||
| ^ Expected argument of type `int`, got `float` | ||
|
||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
|
||
|
||
module = GuppyModule("test") | ||
|
||
T = guppy.type_var("T", module=module) | ||
|
||
|
||
@guppy.declare(module) | ||
def foo(x: T) -> None: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def main(x: float) -> None: | ||
foo[int](x) | ||
|
||
|
||
module.compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Error: Type mismatch (at $FILE:17:12) | ||
| | ||
15 | @guppy(module) | ||
16 | def main(xs: array[int, 42]) -> None: | ||
17 | foo[43](xs) | ||
| ^^ Expected argument of type `array[int, 43]`, got `array[int, | ||
| 42]` | ||
|
||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.std.builtins import array | ||
|
||
module = GuppyModule("test") | ||
|
||
n = guppy.nat_var("n", module=module) | ||
|
||
|
||
@guppy.declare(module) | ||
def foo(x: array[int, n]) -> None: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def main(xs: array[int, 42]) -> None: | ||
foo[43](xs) | ||
|
||
|
||
module.compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Error: Type mismatch (at $FILE:18:6) | ||
| | ||
16 | def main(x: float) -> None: | ||
17 | f = foo[int] | ||
18 | f(x) | ||
| ^ Expected argument of type `int`, got `float` | ||
|
||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
|
||
|
||
module = GuppyModule("test") | ||
|
||
T = guppy.type_var("T", module=module) | ||
|
||
|
||
@guppy.declare(module) | ||
def foo(x: T) -> None: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def main(x: float) -> None: | ||
f = foo[int] | ||
f(x) | ||
|
||
|
||
module.compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Error: Type mismatch (at $FILE:18:23) | ||
| | ||
16 | @guppy(module) | ||
17 | def main(x: int, y: float) -> None: | ||
18 | foo[float, int](x, y) | ||
| ^ Expected argument of type `int`, got `float` | ||
|
||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.std.builtins import array | ||
|
||
module = GuppyModule("test") | ||
|
||
S = guppy.type_var("S", module=module) | ||
T = guppy.type_var("T", module=module) | ||
|
||
|
||
@guppy.declare(module) | ||
def foo(x: S, y: T) -> None: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def main(x: int, y: float) -> None: | ||
foo[float, int](x, y) | ||
|
||
|
||
module.compile() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Error: Not enough type arguments (at $FILE:19:16) | ||
| | ||
17 | @guppy(module) | ||
18 | def main() -> None: | ||
19 | foo[int, int] | ||
| ^ Missing type argument (expected 3, got 2) | ||
|
||
Note: Function signature is `forall S, T, U. (S, T, U) -> None` | ||
|
||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.std.builtins import array | ||
|
||
module = GuppyModule("test") | ||
|
||
S = guppy.type_var("S", module=module) | ||
T = guppy.type_var("T", module=module) | ||
U = guppy.type_var("U", module=module) | ||
|
||
|
||
@guppy.declare(module) | ||
def foo(x: S, y: T, z: U) -> None: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def main() -> None: | ||
foo[int, int] | ||
|
||
|
||
module.compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Error: Not generic (at $FILE:19:4) | ||
| | ||
17 | @guppy(module) | ||
18 | def main() -> None: | ||
19 | foo[int](0) | ||
| ^^^^^^^^ `foo` is not generic, so no type parameters can be provided | ||
|
||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.std.builtins import array | ||
|
||
module = GuppyModule("test") | ||
|
||
S = guppy.type_var("S", module=module) | ||
T = guppy.type_var("T", module=module) | ||
U = guppy.type_var("U", module=module) | ||
|
||
|
||
@guppy.declare(module) | ||
def foo(x: int) -> None: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def main() -> None: | ||
foo[int](0) | ||
|
||
|
||
module.compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Error: Not generic (at $FILE:20:4) | ||
| | ||
18 | def main() -> None: | ||
19 | f = foo | ||
20 | f[int](0) | ||
| ^^^^^^ This function is not generic, so no type parameters can be | ||
| provided | ||
|
||
Guppy compilation failed due to 1 previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.std.builtins import array | ||
|
||
module = GuppyModule("test") | ||
|
||
S = guppy.type_var("S", module=module) | ||
T = guppy.type_var("T", module=module) | ||
U = guppy.type_var("U", module=module) | ||
|
||
|
||
@guppy.declare(module) | ||
def foo(x: int) -> None: | ||
... | ||
|
||
|
||
@guppy(module) | ||
def main() -> None: | ||
f = foo | ||
f[int](0) | ||
|
||
|
||
module.compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Error: Too many type arguments (at $FILE:17:13) | ||
| | ||
15 | @guppy(module) | ||
16 | def main() -> None: | ||
17 | foo[int, float, bool] | ||
| ^^^^^^^^^^^ Unexpected type arguments (expected 1, got 3) | ||
|
||
Note: Function signature is `forall T. T -> None` | ||
|
||
Guppy compilation failed due to 1 previous error |
Oops, something went wrong.