Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Properly report errors for unsupported expressions #692

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading