Skip to content

Commit 04b6a67

Browse files
committed
Add error report for not found vars/vals
1 parent 0c680a4 commit 04b6a67

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,12 @@ object Objects:
336336
def emptyEnv(meth: Symbol)(using Context): Data =
337337
new LocalEnv(Map.empty, meth, NoEnv)(valsMap = mutable.Map.empty, varsMap = mutable.Map.empty)
338338

339-
def valValue(x: Symbol)(using data: Data, ctx: Context): Value =
339+
def valValue(x: Symbol)(using data: Data, ctx: Context, trace: Trace): Value =
340340
data.getVal(x) match
341341
case Some(theValue) =>
342342
theValue
343343
case _ =>
344+
report.warning("[Internal error] Value not found " + x.show + "\nenv = " + data.show + ". Calling trace:\n" + Trace.show, Trace.position)
344345
Bottom
345346

346347
def getVal(x: Symbol)(using data: Data, ctx: Context): Option[Value] = data.getVal(x)
@@ -867,32 +868,28 @@ object Objects:
867868
Bottom
868869
end if
869870
case _ =>
871+
report.warning("[Internal error] Variable not found " + sym.show + "\nenv = " + env.show + ". Calling trace:\n" + Trace.show, Trace.position)
870872
Bottom
871873
else if sym.isPatternBound then
872874
// TODO: handle patterns
873875
Cold
874876
else
875877
given Env.Data = env
876-
try
877-
// Assume forward reference check is doing a good job
878-
val value = Env.valValue(sym)
879-
if isByNameParam(sym) then
880-
value match
881-
case fun: Fun =>
882-
given Env.Data = fun.env
883-
eval(fun.code, fun.thisV, fun.klass)
884-
case Cold =>
885-
report.warning("Calling cold by-name alias. Call trace: \n" + Trace.show, Trace.position)
886-
Bottom
887-
case _: RefSet | _: Ref =>
888-
report.warning("[Internal error] Unexpected by-name value " + value.show + ". Calling trace:\n" + Trace.show, Trace.position)
889-
Bottom
890-
else
891-
value
892-
893-
catch ex =>
894-
report.warning("[Internal error] Not found " + sym.show + "\nenv = " + env.show + ". Calling trace:\n" + Trace.show, Trace.position)
895-
Bottom
878+
// Assume forward reference check is doing a good job
879+
val value = Env.valValue(sym)
880+
if isByNameParam(sym) then
881+
value match
882+
case fun: Fun =>
883+
given Env.Data = fun.env
884+
eval(fun.code, fun.thisV, fun.klass)
885+
case Cold =>
886+
report.warning("Calling cold by-name alias. Call trace: \n" + Trace.show, Trace.position)
887+
Bottom
888+
case _: RefSet | _: Ref =>
889+
report.warning("[Internal error] Unexpected by-name value " + value.show + ". Calling trace:\n" + Trace.show, Trace.position)
890+
Bottom
891+
else
892+
value
896893

897894
case _ =>
898895
if isByNameParam(sym) then
@@ -921,6 +918,7 @@ object Objects:
921918
else
922919
Heap.write(addr, value)
923920
case _ =>
921+
report.warning("[Internal error] Variable not found " + sym.show + "\nenv = " + env.show + ". Calling trace:\n" + Trace.show, Trace.position)
924922

925923
case _ =>
926924
report.warning("Assigning to variables in outer scope. Calling trace:\n" + Trace.show, Trace.position)

0 commit comments

Comments
 (0)