Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 4a4c88e

Browse files
committed
Fix interaction between vars and DeclaredSingletonTypes.
1 parent b7f4946 commit 4a4c88e

File tree

8 files changed

+6
-14
lines changed

8 files changed

+6
-14
lines changed

src/compiler/scala/reflect/reify/codegen/GenTypes.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ trait GenTypes {
5252
reifyBuildCall(nme.SuperType, thistpe, supertpe)
5353
case tpe @ SingleType(pre, sym) =>
5454
reifyBuildCall(nme.SingleType, pre, sym)
55-
// TODO (folone): ConstantType folding?
56-
case tpe @ ConstantType(value) if !tpe.isDeclaredSingleton =>
55+
case tpe @ ConstantType(value) if !tpe.asDeclaredSingleton.isDefined =>
5756
mirrorBuildCall(nme.ConstantType, reifyProduct(value))
5857
case tpe @ TypeRef(pre, sym, args) =>
5958
reifyBuildCall(nme.TypeRef, pre, sym, args)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,6 @@ abstract class Constructors extends Statics with Transform with ast.TreeDSL {
640640
// methods with constant result type get literals as their body
641641
// all methods except the primary constructor go into template
642642
stat.symbol.tpe match {
643-
// TODO (folone): inlining of defs with literal-based singleton type results?
644643
case MethodType(List(), tp @ ConstantType(c)) =>
645644
defBuf += deriveDefDef(stat)(Literal(c) setPos _.pos setType tp)
646645
case _ =>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,7 @@ abstract class Erasure extends AddInterfaces
535535
} else bridgingCall
536536
}
537537
val rhs = member.tpe match {
538-
// TODO (folone): inlining of defs with literal-based singleton type results?
539-
case MethodType(Nil, tp @ ConstantType(c)) if !tp.isDeclaredSingleton => Literal(c)
538+
case MethodType(Nil, tp @ ConstantType(c)) if !tp.asDeclaredSingleton.isDefined => Literal(c)
540539
case _ =>
541540
val sel: Tree = Select(This(root), member)
542541
val bridgingCall = (sel /: bridge.paramss)((fun, vparams) => Apply(fun, vparams map Ident))

src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
496496
val alternativesSupported = true
497497
val canJump = true
498498

499-
// TODO (folone): ConstantType folding?
500499
// Constant folding sets the type of a constant tree to `ConstantType(Constant(folded))`
501500
// The tree itself can be a literal, an ident, a selection, ...
502501
object SwitchablePattern { def unapply(pat: Tree): Option[Tree] = pat.tpe match {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ trait Infer extends Checkable {
477477
else Some(
478478
if (targ.typeSymbol == RepeatedParamClass) targ.baseType(SeqClass)
479479
else if (targ.typeSymbol == JavaRepeatedParamClass) targ.baseType(ArrayClass)
480-
else if (targ.isDeclaredSingleton) targ
480+
else if (targ.asDeclaredSingleton.isDefined) targ
481481
// this infers Foo.type instead of "object Foo" (see also widenIfNecessary)
482482
else if (targ.typeSymbol.isModuleClass || tvar.constr.avoidWiden) targ
483483
else targ.widen

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@ trait TypeDiagnostics {
504504
&& !targets(m)
505505
&& !(m.name == nme.WILDCARD) // e.g. val _ = foo
506506
&& !ignoreNames(m.name.toTermName) // serialization methods
507-
// TODO (folone): inlining of defs with literal-based singleton type results?
508507
&& !isConstantType(m.info.resultType) // subject to constant inlining
509508
&& !treeTypes.exists(_ contains m) // e.g. val a = new Foo ; new a.Bar
510509
)

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
996996
if (mode.inPatternMode && isPopulatedPattern)
997997
return tree
998998

999-
// TODO (folone): ConstantType folding?
1000999
val tree1 = constfold(tree, pt) // (10) (11)
10011000
if (tree1.tpe <:< pt)
10021001
return adapt(tree1, mode, pt, original)
@@ -1097,7 +1096,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
10971096
} else tree.tpe match {
10981097
case atp @ AnnotatedType(_, _) if canAdaptAnnotations(tree, this, mode, pt) => // (-1)
10991098
adaptAnnotations(tree, this, mode, pt)
1100-
case ct @ ConstantType(value) if mode.inNone(TYPEmode | FUNmode) && (ct <:< pt) && canAdaptConstantTypeToLiteral && !ct.isDeclaredSingleton => // (0)
1099+
case ct @ ConstantType(value) if mode.inNone(TYPEmode | FUNmode) && (ct <:< pt) && canAdaptConstantTypeToLiteral && !ct.asDeclaredSingleton.isDefined => // (0)
11011100
adaptConstant(value)
11021101
case OverloadedType(pre, alts) if !mode.inFunMode => // (1)
11031102
inferExprAlternative(tree, pt)
@@ -3479,7 +3478,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
34793478
ErroneousAnnotation
34803479
}
34813480

3482-
// TODO (folone): ConstantType folding?
34833481
/* Calling constfold right here is necessary because some trees (negated
34843482
* floats and literals in particular) are not yet folded.
34853483
*/
@@ -3543,7 +3541,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
35433541
case Typed(t, _) =>
35443542
tree2ConstArg(t, pt)
35453543

3546-
// TODO (folone): ConstantType folding?
35473544
case tree =>
35483545
tryConst(tree, pt)
35493546
}

test/files/run/42.type.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object Test {
1616

1717
type Null = null.type
1818

19-
//var x: 3.type = 3
19+
var x: 3.type = 3
2020
/*
2121
scala> x = 42
2222
<console>:8: error: type mismatch;
@@ -57,7 +57,7 @@ object Test {
5757
}
5858

5959
def main(args: Array[String]): Unit = {
60-
//println(f(1))
60+
// println(f(1))
6161
// println(f(5))
6262
println((g(1), g(5), g(7)))
6363
noisyIdentity(1)

0 commit comments

Comments
 (0)