@@ -744,7 +744,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
744
744
/** Perform the following adaptations of expression, pattern or type `tree` wrt to
745
745
* given mode `mode` and given prototype `pt`:
746
746
* (-1) For expressions with annotated types, let AnnotationCheckers decide what to do
747
- * (0) Convert expressions with constant types to literals (unless in interactive/scaladoc mode)
747
+ * (0) Convert expressions with constant types to literals (unless in interactive/scaladoc mode or dealing with a singleton type )
748
748
* (1) Resolve overloading, unless mode contains FUNmode
749
749
* (2) Apply parameterless functions
750
750
* (3) Apply polymorphic types to fresh instances of their type parameters and
@@ -996,6 +996,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
996
996
if (mode.inPatternMode && isPopulatedPattern)
997
997
return tree
998
998
999
+ // TODO (folone): ConstantType folding?
999
1000
val tree1 = constfold(tree, pt) // (10) (11)
1000
1001
if (tree1.tpe <:< pt)
1001
1002
return adapt(tree1, mode, pt, original)
@@ -1096,7 +1097,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
1096
1097
} else tree.tpe match {
1097
1098
case atp @ AnnotatedType (_, _) if canAdaptAnnotations(tree, this , mode, pt) => // (-1)
1098
1099
adaptAnnotations(tree, this , mode, pt)
1099
- case ct @ ConstantType (value) if mode.inNone(TYPEmode | FUNmode ) && (ct <:< pt) && canAdaptConstantTypeToLiteral => // (0)
1100
+ case ct @ ConstantType (value) if mode.inNone(TYPEmode | FUNmode ) && (ct <:< pt) && canAdaptConstantTypeToLiteral && ! ct.isDeclaredSingleton => // (0)
1100
1101
adaptConstant(value)
1101
1102
case OverloadedType (pre, alts) if ! mode.inFunMode => // (1)
1102
1103
inferExprAlternative(tree, pt)
@@ -3478,6 +3479,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
3478
3479
ErroneousAnnotation
3479
3480
}
3480
3481
3482
+ // TODO (folone): ConstantType folding?
3481
3483
/* Calling constfold right here is necessary because some trees (negated
3482
3484
* floats and literals in particular) are not yet folded.
3483
3485
*/
@@ -3541,6 +3543,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
3541
3543
case Typed (t, _) =>
3542
3544
tree2ConstArg(t, pt)
3543
3545
3546
+ // TODO (folone): ConstantType folding?
3544
3547
case tree =>
3545
3548
tryConst(tree, pt)
3546
3549
}
@@ -5107,11 +5110,13 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
5107
5110
}
5108
5111
5109
5112
def typedSingletonTypeTree (tree : SingletonTypeTree ) = {
5110
- val refTyped =
5111
- context.withImplicitsDisabled {
5112
- typed(tree.ref, MonoQualifierModes | mode.onlyTypePat, AnyRefTpe )
5113
- }
5114
-
5113
+ val refTyped = context.withImplicitsDisabled {
5114
+ typed(tree.ref, MonoQualifierModes | mode.onlyTypePat, AnyClass .tpe)
5115
+ }
5116
+ tree setType {
5117
+ if (tree.isLiteral) refTyped.tpe.resultType.asDeclaredSingleton
5118
+ else refTyped.tpe.resultType
5119
+ }
5115
5120
if (! refTyped.isErrorTyped)
5116
5121
tree setType refTyped.tpe.resultType
5117
5122
0 commit comments