Skip to content

Commit

Permalink
fix: Detect unsupported default arguments (#659)
Browse files Browse the repository at this point in the history
Fixes #658
  • Loading branch information
mark-koch authored Nov 25, 2024
1 parent 4ecb5f2 commit 94ac7e3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions guppylang/checker/func_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def check_signature(func_def: ast.FunctionDef, globals: Globals) -> FunctionType
raise GuppyError(UnsupportedError(func_def.args.vararg, "Variadic args"))
if func_def.args.kwarg is not None:
raise GuppyError(UnsupportedError(func_def.args.kwarg, "Keyword args"))
if func_def.args.defaults:
raise GuppyError(
UnsupportedError(func_def.args.defaults[0], "Default arguments")
)
if func_def.returns is None:
err = MissingReturnAnnotationError(func_def)
# TODO: Error location is incorrect
Expand Down
8 changes: 8 additions & 0 deletions tests/error/misc_errors/default_arg.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Error: Unsupported (at $FILE:5:26)
|
3 |
4 | @compile_guppy
5 | def foo(x: int, y: bool = True) -> int:
| ^^^^ Default arguments are not supported

Guppy compilation failed due to 1 previous error
6 changes: 6 additions & 0 deletions tests/error/misc_errors/default_arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from tests.util import compile_guppy


@compile_guppy
def foo(x: int, y: bool = True) -> int:
return x

0 comments on commit 94ac7e3

Please sign in to comment.