Skip to content

Commit

Permalink
fix: Properly report errors for unsupported expressions (#692)
Browse files Browse the repository at this point in the history
Fixes #691
  • Loading branch information
mark-koch authored Dec 6, 2024
1 parent b21b7e1 commit 7f24264
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions guppylang/checker/expr_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,10 @@ def visit_IfExp(self, node: ast.IfExp) -> tuple[ast.expr, Type]:
f"`{ast.unparse(node)}`"
)

def generic_visit(self, node: ast.expr) -> NoReturn:
"""Called if no explicit visitor function exists for a node."""
raise GuppyError(UnsupportedError(node, "This expression", singular=True))


def check_type_against(
act: Type, exp: Type, node: AstNode, kind: str = "expression"
Expand Down
8 changes: 8 additions & 0 deletions tests/error/misc_errors/unsupported_expr.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Error: Unsupported (at $FILE:7:14)
|
5 | @compile_guppy
6 | def foo(xs: array[int, 1]) -> tuple[int, int]:
7 | return 0, *xs
| ^^^ This expression is not supported

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


@compile_guppy
def foo(xs: array[int, 1]) -> tuple[int, int]:
return 0, *xs

0 comments on commit 7f24264

Please sign in to comment.