Skip to content

Commit 191085d

Browse files
committed
Code refactoring
1 parent 8be99ff commit 191085d

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ object Semantic:
479479
def add(node: Tree): Trace = trace :+ node
480480
def toVector: Vector[Tree] = trace
481481

482+
def show(using trace: Trace, ctx: Context): String = buildStacktrace(trace, "\n")
483+
484+
def position(using trace: Trace): Tree = trace.last
482485
type Trace = Trace.Trace
483486

484487
import Trace.*
@@ -693,15 +696,15 @@ object Semantic:
693696
Hot
694697
else
695698
if ref.klass.isSubClass(receiver.widenSingleton.classSymbol) then
696-
report.error("Unexpected resolution failure: ref.klass = " + ref.klass.show + ", field = " + field.show + buildStacktrace(trace.toVector, "\n"))
699+
report.error("[Internal error] Unexpected resolution failure: ref.klass = " + ref.klass.show + ", field = " + field.show + Trace.show, Trace.position)
697700
Hot
698701
else
699702
// This is possible due to incorrect type cast.
700703
// See tests/init/pos/Type.scala
701704
Hot
702705

703706
case fun: Fun =>
704-
report.error("[Internal error] unexpected tree in selecting a function, fun = " + fun.expr.show, fun.expr)
707+
report.error("[Internal error] unexpected tree in selecting a function, fun = " + fun.expr.show + Trace.show, fun.expr)
705708
Hot
706709

707710
case RefSet(refs) =>
@@ -826,7 +829,7 @@ object Semantic:
826829
value.select(target, receiver, needResolve = false)
827830
else
828831
if ref.klass.isSubClass(receiver.widenSingleton.classSymbol) then
829-
report.error("Unexpected resolution failure: ref.klass = " + ref.klass.show + ", meth = " + meth.show + buildStacktrace(trace.toVector, "\n"))
832+
report.error("Unexpected resolution failure: ref.klass = " + ref.klass.show + ", meth = " + meth.show + Trace.show, Trace.position)
830833
Hot
831834
else
832835
// This is possible due to incorrect type cast.
@@ -856,7 +859,7 @@ object Semantic:
856859

857860
value match {
858861
case Hot | Cold | _: RefSet | _: Fun =>
859-
report.error("unexpected constructor call, meth = " + ctor + ", value = " + value, trace.toVector.last)
862+
report.error("[Internal error] unexpected constructor call, meth = " + ctor + ", value = " + value + Trace.show, Trace.position)
860863
Hot
861864

862865
case ref: Warm if ref.isPopulatingParams =>
@@ -963,7 +966,7 @@ object Semantic:
963966
warm
964967

965968
case Fun(body, thisV, klass) =>
966-
report.error("[Internal error] unexpected tree in instantiating a function, fun = " + body.show, trace.toVector.last)
969+
report.error("[Internal error] unexpected tree in instantiating a function, fun = " + body.show + Trace.show, Trace.position)
967970
Hot
968971

969972
case RefSet(refs) =>
@@ -983,7 +986,7 @@ object Semantic:
983986
case Hot => Hot
984987
case ref: Ref => ref.objekt.field(sym)
985988
case _ =>
986-
report.error("[Internal error] unexpected this value accessing local variable, sym = " + sym.show + ", thisValue = " + thisValue2.show, trace.toVector.last)
989+
report.error("[Internal error] unexpected this value accessing local variable, sym = " + sym.show + ", thisValue = " + thisValue2.show + Trace.show, Trace.position)
987990
Hot
988991
else if sym.is(Flags.Param) then
989992
Hot
@@ -1001,7 +1004,7 @@ object Semantic:
10011004
case ref: Ref => eval(vdef.rhs, ref, enclosingClass)
10021005

10031006
case _ =>
1004-
report.error("[Internal error] unexpected this value when accessing local variable, sym = " + sym.show + ", thisValue = " + thisValue2.show, trace.toVector.last)
1007+
report.error("[Internal error] unexpected this value when accessing local variable, sym = " + sym.show + ", thisValue = " + thisValue2.show + Trace.show, Trace.position)
10051008
Hot
10061009
end match
10071010

@@ -1469,7 +1472,7 @@ object Semantic:
14691472
Hot
14701473

14711474
case _ =>
1472-
report.error("[Internal error] unexpected tree", expr)
1475+
report.error("[Internal error] unexpected tree" + Trace.show, expr)
14731476
Hot
14741477

14751478
/** Handle semantics of leaf nodes */
@@ -1498,7 +1501,7 @@ object Semantic:
14981501
Hot
14991502

15001503
case _ =>
1501-
report.error("[Internal error] unexpected type " + tp, trace.toVector.last)
1504+
report.error("[Internal error] unexpected type " + tp + Trace.show, Trace.position)
15021505
Hot
15031506
}
15041507

@@ -1513,15 +1516,15 @@ object Semantic:
15131516
val obj = ref.objekt
15141517
val outerCls = klass.owner.lexicallyEnclosingClass.asClass
15151518
if !obj.hasOuter(klass) then
1516-
val error = PromoteError("[Internal error] outer not yet initialized, target = " + target + ", klass = " + klass + ", object = " + obj, trace.toVector)
1517-
report.error(error.show, trace.toVector.last)
1519+
val error = "[Internal error] outer not yet initialized, target = " + target + ", klass = " + klass + ", object = " + obj + Trace.show
1520+
report.error(error, Trace.position)
15181521
Hot
15191522
else
15201523
resolveThis(target, obj.outer(klass), outerCls)
15211524
case RefSet(refs) =>
15221525
refs.map(ref => resolveThis(target, ref, klass)).join
15231526
case fun: Fun =>
1524-
report.error("[Internal error] unexpected thisV = " + thisV + ", target = " + target.show + ", klass = " + klass.show, trace.toVector.last)
1527+
report.error("[Internal error] unexpected thisV = " + thisV + ", target = " + target.show + ", klass = " + klass.show + Trace.show, Trace.position)
15251528
Cold
15261529
case Cold => Cold
15271530

0 commit comments

Comments
 (0)