Skip to content

Commit afbf0ca

Browse files
committed
Simplify code.
1 parent 6af6076 commit afbf0ca

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,7 @@ object Semantic:
738738
else
739739
reporter.reportAll(tryReporter.errors)
740740
extendTrace(ddef) {
741-
val rhs = ddef.getRhs
742-
eval(rhs, ref, cls, cacheResult = true)
741+
eval(ddef.getRhs, ref, cls, cacheResult = true)
743742
}
744743
else if ref.canIgnoreMethodCall(target) then
745744
Hot
@@ -801,13 +800,10 @@ object Semantic:
801800
val tpl = cls.defTree.asInstanceOf[TypeDef].rhs.asInstanceOf[Template]
802801
extendTrace(cls.defTree) { init(tpl, ref, cls) }
803802
else
804-
val rhs = ddef.getRhs
805-
if rhs.isEmpty then Hot
806-
else
807-
val initCall = rhs match
808-
case Block(call :: _, _) => call
809-
case call => call
810-
extendTrace(ddef) { eval(initCall, ref, cls) }
803+
val initCall = ddef.getRhs match
804+
case Block(call :: _, _) => call
805+
case call => call
806+
extendTrace(ddef) { eval(initCall, ref, cls) }
811807
end if
812808
else
813809
Hot
@@ -823,10 +819,7 @@ object Semantic:
823819
extendTrace(cls.defTree) { eval(tpl, ref, cls, cacheResult = true) }
824820
ref
825821
else
826-
extendTrace(ddef) {
827-
val rhs = ddef.getRhs
828-
eval(rhs, ref, cls, cacheResult = true)
829-
}
822+
extendTrace(ddef) { eval(ddef.getRhs, ref, cls, cacheResult = true) }
830823
else if ref.canIgnoreMethodCall(ctor) then
831824
Hot
832825
else
@@ -936,9 +929,7 @@ object Semantic:
936929

937930
case Cold => Cold
938931

939-
case ref: Ref =>
940-
val rhs = vdef.getRhs
941-
eval(rhs, ref, enclosingClass, cacheResult = sym.is(Flags.Lazy))
932+
case ref: Ref => eval(vdef.getRhs, ref, enclosingClass, cacheResult = sym.is(Flags.Lazy))
942933
case _ =>
943934
report.warning("[Internal error] unexpected this value when accessing local variable, sym = " + sym.show + ", thisValue = " + thisValue2.show + Trace.show, Trace.position)
944935
Hot
@@ -1352,12 +1343,10 @@ object Semantic:
13521343
}
13531344

13541345
case closureDef(ddef) =>
1355-
val rhs = ddef.getRhs
1356-
Fun(rhs, thisV, klass)
1346+
Fun(ddef.getRhs, thisV, klass)
13571347

13581348
case PolyFun(ddef) =>
1359-
val rhs = ddef.getRhs
1360-
Fun(rhs, thisV, klass)
1349+
Fun(ddef.getRhs, thisV, klass)
13611350

13621351
case Block(stats, expr) =>
13631352
eval(stats, thisV, klass)
@@ -1409,8 +1398,7 @@ object Semantic:
14091398

14101399
case vdef : ValDef =>
14111400
// local val definition
1412-
val rhs = vdef.getRhs
1413-
eval(rhs, thisV, klass)
1401+
eval(vdef.getRhs, thisV, klass)
14141402

14151403
case ddef : DefDef =>
14161404
// local method

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,13 @@ class CompilationTests {
275275
val a0 = defaultOutputDir + tastyErrorGroup + "/A/v0/A"
276276
val a1 = defaultOutputDir + tastyErrorGroup + "/A/v1/A"
277277
val b1 = defaultOutputDir + tastyErrorGroup + "/B/v1/B"
278-
val a0b1 = a0 + ":" + b1
279278

280279
val tests = List(
281280
compileFile("tests/init/tasty-error/v1/A.scala", tastyErrorOptions)(tastyErrorGroup),
282281
compileFile("tests/init/tasty-error/v1/B.scala", tastyErrorOptions.withClasspath(a1))(tastyErrorGroup),
283282
compileFile("tests/init/tasty-error/v0/A.scala", tastyErrorOptions)(tastyErrorGroup),
284283
).map(_.keepOutput.checkCompile())
285-
compileFile("tests/init/tasty-error/Main.scala", tastyErrorOptions.withClasspath(a0b1))(tastyErrorGroup).checkExpectedErrors()
284+
compileFile("tests/init/tasty-error/Main.scala", tastyErrorOptions.withClasspath(a0 + ":" + b1))(tastyErrorGroup).checkExpectedErrors()
286285

287286
tests.foreach(_.delete())
288287
}

0 commit comments

Comments
 (0)