Skip to content

Commit c74a9b1

Browse files
committed
Avoid typechecking val and def tpt-s twice
1 parent 541192b commit c74a9b1

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

src/compiler/scala/tools/nsc/typechecker/Namers.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,11 @@ trait Namers extends MethodSynthesis {
13111311

13121312
val resTpGiven =
13131313
if (tpt.isEmpty) WildcardType
1314-
else typer.typedType(tpt).tpe
1314+
else {
1315+
val tptTyped = typer.typedType(tpt)
1316+
context.unit.transformed(tpt) = tptTyped
1317+
tptTyped.tpe
1318+
}
13151319

13161320

13171321
// ignore missing types unless we can look to overridden method to recover the missing information
@@ -1723,7 +1727,11 @@ trait Namers extends MethodSynthesis {
17231727

17241728
tptFromRhsUnderPt
17251729
}
1726-
} else typer.typedType(tpt).tpe
1730+
} else {
1731+
val tptTyped = typer.typedType(tpt)
1732+
context.unit.transformed(tpt) = tptTyped
1733+
tptTyped.tpe
1734+
}
17271735

17281736
// println(s"val: $result / ${vdef.tpt.tpe} / ")
17291737

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
20872087
} else typedModifiers(vdef.mods)
20882088

20892089
sym.annotations.map(_.completeInfo())
2090-
val tpt1 = checkNoEscaping.privates(this, sym, typedType(vdef.tpt))
2090+
val tpt1 = checkNoEscaping.privates(this, sym, transformedOr(vdef.tpt, typedType(vdef.tpt)))
20912091
checkNonCyclic(vdef, tpt1)
20922092

20932093
// allow trait accessors: it's the only vehicle we have to hang on to annotations that must be passed down to
@@ -2315,7 +2315,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
23152315
if (isRepeatedParamType(vparam1.symbol.tpe))
23162316
StarParamNotLastError(vparam1)
23172317

2318-
val tpt1 = checkNoEscaping.privates(this, meth, typedType(ddef.tpt))
2318+
val tpt1 = checkNoEscaping.privates(this, meth, transformedOr(ddef.tpt, typedType(ddef.tpt)))
23192319
checkNonCyclic(ddef, tpt1)
23202320
ddef.tpt.setType(tpt1.tpe)
23212321
val typedMods = typedModifiers(ddef.mods)

test/files/neg/t5148.check

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
t5148.scala:4: error: Symbol 'term scala.tools.nsc.interpreter.IMain.memberHandlers' is missing from the classpath.
2-
This symbol is required by 'method scala.tools.nsc.interpreter.Imports.allReqAndHandlers'.
3-
Make sure that term memberHandlers is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
1+
t5148.scala:4: error: Symbol 'term scala.tools.nsc.interpreter.IMain.global' is missing from the classpath.
2+
This symbol is required by 'method scala.tools.nsc.interpreter.Imports.membersAtPickler'.
3+
Make sure that term global is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
44
A full rebuild may help if 'Imports.class' was compiled against an incompatible version of scala.tools.nsc.interpreter.IMain.
55
class IMain extends Imports
66
^
7-
t5148.scala:4: error: Symbol 'type scala.tools.nsc.interpreter.IMain.Request.Wrapper' is missing from the classpath.
8-
This symbol is required by 'value scala.tools.nsc.interpreter.Imports.wrapper'.
9-
Make sure that type Wrapper is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
10-
A full rebuild may help if 'Imports.class' was compiled against an incompatible version of scala.tools.nsc.interpreter.IMain.Request.
11-
class IMain extends Imports
12-
^
13-
two errors found
7+
one error found

test/files/run/reflection-names.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
(java.lang.String,bc)
2-
(scala.reflect.internal.Names$TermName,bc)
3-
(scala.reflect.internal.Names$TypeName,bc)
4-
(scala.reflect.internal.Names$TypeName,bc)
2+
(scala.reflect.internal.NameTable$TermName,bc)
3+
(scala.reflect.internal.NameTable$TypeName,bc)
4+
(scala.reflect.internal.NameTable$TypeName,bc)

test/junit/scala/reflect/internal/PrintersTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ class BasePrintTest {
332332
@Test def testFunc2 = assertResultCode(
333333
code = "val sum: Seq[Int] => Int = _ reduceLeft (_+_)")(
334334
parsedCode = "val sum: _root_.scala.Function1[Seq[Int], Int] = ((x$1) => x$1.reduceLeft(((x$2, x$3) => x$2.+(x$3))))",
335-
typedCode = "val sum: _root_.scala.Function1[scala.`package`.Seq[scala.Int], scala.Int] = ((x$1: Seq[Int]) => x$1.reduceLeft[Int](((x$2: Int, x$3: Int) => x$2.+(x$3))))")
335+
typedCode = "val sum: scala.Function1[scala.`package`.Seq[scala.Int], scala.Int] = ((x$1: Seq[Int]) => x$1.reduceLeft[Int](((x$2: Int, x$3: Int) => x$2.+(x$3))))")
336336

337337
@Test def testFunc3 = assertResultCode(
338338
code = "List(1, 2, 3) map (_ - 1)")(

0 commit comments

Comments
 (0)