Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-koch committed Jan 30, 2024
1 parent 5fa46f9 commit 829bf20
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion guppylang/checker/expr_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,9 @@ def _python_list_to_guppy_type(
return None
for v in rest:
ty = python_value_to_guppy_type(v, node, globals)
if ty is None or (subst := unify(ty, el_ty, {})) is None:
if ty is None:
return None
if (subst := unify(ty, el_ty, {})) is None:
raise GuppyError("Python list contains elements with different types", node)
el_ty = el_ty.substitute(subst)
return ListType(el_ty)
2 changes: 1 addition & 1 deletion tests/error/py_errors/list_different_tys.err
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Guppy compilation failed. Error in file $FILE:6
5: def foo() -> int:
6: return py([1, 1.0])
^^^^^^^^^^^^
GuppyError: Python expression of type `<class 'list'>` is not supported by Guppy
GuppyError: Python list contains elements with different types

0 comments on commit 829bf20

Please sign in to comment.