Skip to content

Commit

Permalink
Make constants printable
Browse files Browse the repository at this point in the history
Since we print them in one of the new error messages
  • Loading branch information
mark-koch committed Dec 4, 2024
1 parent 04c376e commit 905d894
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions guppylang/tys/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def unsolved_vars(self) -> set[ExistentialVar]:
"""The existential type variables contained in this constant."""
return set()

def __str__(self) -> str:
from guppylang.tys.printing import TypePrinter

return TypePrinter().visit(self.cast())

def visit(self, visitor: Visitor) -> None:
"""Accepts a visitor on this constant."""
visitor.visit(self)
Expand Down
4 changes: 2 additions & 2 deletions guppylang/tys/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from guppylang.error import InternalGuppyError
from guppylang.tys.arg import ConstArg, TypeArg
from guppylang.tys.const import ConstValue
from guppylang.tys.const import Const, ConstValue
from guppylang.tys.param import ConstParam, TypeParam
from guppylang.tys.ty import (
FunctionType,
Expand Down Expand Up @@ -53,7 +53,7 @@ def _fresh_name(self, display_name: str) -> str:
self.counter[display_name] += 1
return indexed

def visit(self, ty: Type) -> str:
def visit(self, ty: Type | Const) -> str:
return self._visit(ty, False)

@singledispatchmethod
Expand Down

0 comments on commit 905d894

Please sign in to comment.