File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
src/compiler/scala/tools/nsc/typechecker Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -871,15 +871,16 @@ trait Namers extends MethodSynthesis {
871871 // - We don't need to call dropIllegalStarTypes on a ref to a module class, do we? Where would the stars be? In the prefix?
872872
873873 // We're inferring the result type of a stable symbol, and the type doesn't refer to a hidden symbol
874- val mayKeepSingletonType = sym.isStable && ! refersToSymbolLessAccessibleThan(tpe, sym)
875-
874+ // Also widen constant/literal return types of non-final definitions
875+ val mayKeepSingletonType = (sym.isStable &&
876+ (sym.isFinal || ! (tpe.isInstanceOf [ConstantType ] || tpe.isInstanceOf [LiteralType ])) &&
877+ ! refersToSymbolLessAccessibleThan(tpe, sym))
878+
879+ // on't change the type if the definition can keep its inferred singleton type,
880+ // or widening would mean no longer conforming to the expected type.
881+ // Otherwise, widen.
876882 // (OPT: 99.99% of the time, pt will be WildcardType)
877- @ inline def cannotWiden = (pt ne WildcardType ) && ! (tpe.widen <:< pt)
878-
879- // If the definition can keep its inferred singleton type,
880- // or widening would mean no longer conforming to the expected type,
881- // we must still deconst unless it's a final val. Otherwise, widen.
882- if (mayKeepSingletonType || cannotWiden) { if (sym.isFinal) tpe else tpe.deconst }
883+ if (mayKeepSingletonType || (pt ne WildcardType ) && ! (tpe.widen <:< pt)) tpe
883884 else tpe.widen
884885 } else {
885886 val shouldWiden = (
You can’t perform that action at this time.
0 commit comments