Commit 7d69d7e2 authored by Tom Niget's avatar Tom Niget

Extract method for better traceback

parent a93954c6
......@@ -97,7 +97,9 @@ def exception_hook(exc_type, exc_value, tb):
for i, line in enumerate(hg[start:last_node.end_lineno + CONTEXT_SIZE]):
erroneous = last_node.lineno <= offset + i <= last_node.end_lineno
indicator = cf.white(" →") if erroneous else " "
disp = f"\x1b[24m{indicator}{cf.white}{(offset + i):>4}{cf.red if erroneous else cf.reset}{cf.reset} {line}\x1b[24m"
bar = " ▎"
# bar = "│" if erroneous else "┊"
disp = f"\x1b[24m{indicator}{cf.white}{(offset + i):>4}{cf.red if erroneous else cf.reset}{bar}{cf.reset} {line}\x1b[24m"
print(disp)
# print(repr(disp))
print()
......
......@@ -28,7 +28,6 @@ class ScoperVisitor(NodeVisitorSeq):
if not block:
return
TB = f"running type analysis on block starting with {highlight(block[0])}"
from transpiler.phases.typing.block import ScoperBlockVisitor
self.fdecls = []
for b in block:
self.visit(b)
......@@ -40,13 +39,7 @@ class ScoperVisitor(NodeVisitorSeq):
for node, rtype in old_list:
from transpiler.exceptions import CompileError
try:
for b in node.body:
decls = {}
visitor = ScoperBlockVisitor(node.inner_scope, decls)
visitor.visit(b)
b.decls = decls
if not node.inner_scope.has_return:
rtype.unify(TY_NONE) # todo: properly indicate missing return
self.visit_function_definition(node, rtype)
except CompileError as e:
new_list.append((node, rtype))
if not exc:
......@@ -58,3 +51,15 @@ class ScoperVisitor(NodeVisitorSeq):
old_list = new_list
exc = None
def visit_function_definition(self, node, rtype):
TB = f"running type analysis on the body of {highlight(node)}"
TB_NODE = node
from transpiler.phases.typing.block import ScoperBlockVisitor
for b in node.body:
decls = {}
visitor = ScoperBlockVisitor(node.inner_scope, decls)
visitor.visit(b)
b.decls = decls
if not node.inner_scope.has_return:
rtype.unify(TY_NONE) # todo: properly indicate missing return
......@@ -174,8 +174,9 @@ class TypeOperator(BaseType, ABC):
def unify_internal(self, other: BaseType):
from transpiler.phases.typing.exceptions import TypeMismatchError, TypeMismatchKind
if from_node := next(filter(None, (getattr(x, "from_node", None) for x in (other, self))), None):
TB_NODE = from_node
# TODO(zdimension): this is really broken... but it would be nice
# if from_node := next(filter(None, (getattr(x, "from_node", None) for x in (other, self))), None):
# TB_NODE = from_node
if not isinstance(other, TypeOperator):
raise TypeMismatchError(self, other, TypeMismatchKind.DIFFERENT_TYPE)
if other.is_protocol and not self.is_protocol:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment