Skip to content

Commit 6051b28

Browse files
committed
deal with constant methods in uncurry instead of ctors
1 parent 51f59df commit 6051b28

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/compiler/scala/tools/nsc/transform/Constructors.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,6 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
693693
for (stat <- stats) {
694694
val sym = stat.symbol
695695
stat match {
696-
// TODO what is this doing in Constructors? I'd expect it much earlier -- erasure? uncurry?
697-
case dd@ DefDef(_,_,_,_,_,rhs) if sym.info.params.isEmpty && sym.info.resultType.isInstanceOf[ConstantType] =>
698-
defBuf += deriveDefDef(dd)(rhs => gen.mkAttributedQualifier(sym.info.resultType) setPos rhs.pos )
699-
700696
// all methods except the primary constructor go into template
701697
case _: DefDef if sym.isConstructor => if (sym ne primaryConstr.symbol) auxConstructorBuf += stat
702698

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,21 @@ abstract class UnCurry extends InfoTransform
593593
(vparamss1, rhs0)
594594
}
595595

596+
// We know newParamss.length == 1
597+
// A no-arg method with ConstantType result type can safely be
598+
// reduced to the corresponding Literal (only pure methods are typed as ConstantType).
599+
// We could also do this for methods with arguments, after ensuring the arguments are not referenced.
600+
val literalRhsIfConst =
601+
if (newParamss.head.isEmpty && dd.symbol.info.resultType.isInstanceOf[ConstantType])
602+
gen.mkAttributedQualifier(dd.symbol.info.resultType) setPos newRhs.pos
603+
else newRhs
604+
605+
596606
val flatdd = copyDefDef(dd)(
597607
vparamss = newParamss,
598608
rhs = nonLocalReturnKeys get dd.symbol match {
599-
case Some(k) => atPos(newRhs.pos)(nonLocalReturnTry(newRhs, k, dd.symbol))
600-
case None => newRhs
609+
case Some(k) => atPos(newRhs.pos)(nonLocalReturnTry(literalRhsIfConst, k, dd.symbol))
610+
case None => literalRhsIfConst
601611
}
602612
)
603613
addJavaVarargsForwarders(dd, flatdd)

0 commit comments

Comments
 (0)