forked from M-Labs/artiq
transforms.inferencer: give a suggestion on "raise Exception".
This commit is contained in:
parent
641ef57458
commit
3573a8750a
|
@ -1221,10 +1221,19 @@ class Inferencer(algorithm.Visitor):
|
||||||
if node.exc is not None:
|
if node.exc is not None:
|
||||||
exc_type = node.exc.type
|
exc_type = node.exc.type
|
||||||
if not types.is_var(exc_type) and not builtins.is_exception(exc_type):
|
if not types.is_var(exc_type) and not builtins.is_exception(exc_type):
|
||||||
|
if types.is_exn_constructor(exc_type):
|
||||||
|
notes = [diagnostic.Diagnostic("note",
|
||||||
|
"this value is an exception constructor; use {suggestion} instead",
|
||||||
|
{"suggestion": node.exc.loc.source() + "()"},
|
||||||
|
node.exc.loc)]
|
||||||
|
else:
|
||||||
|
notes = []
|
||||||
|
|
||||||
diag = diagnostic.Diagnostic("error",
|
diag = diagnostic.Diagnostic("error",
|
||||||
"cannot raise a value of type {type}, which is not an exception",
|
"cannot raise a value of type {type}, which is not an exception",
|
||||||
{"type": types.TypePrinter().name(exc_type)},
|
{"type": types.TypePrinter().name(exc_type)},
|
||||||
node.exc.loc)
|
node.loc,
|
||||||
|
notes=notes)
|
||||||
self.engine.process(diag)
|
self.engine.process(diag)
|
||||||
|
|
||||||
def visit_Assert(self, node):
|
def visit_Assert(self, node):
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# RUN: %python -m artiq.compiler.testbench.signature +diag %s >%t
|
||||||
|
# RUN: OutputCheck %s --file-to-check=%t
|
||||||
|
|
||||||
|
# CHECK-L: ${LINE:+1}: note: this value is an exception constructor; use IndexError() instead
|
||||||
|
raise IndexError
|
Loading…
Reference in New Issue