Skip to content

Commit f67a7bc

Browse files
committed
widenIfNecessary: we have bootstrap
1 parent 61a16f5 commit f67a7bc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff 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 = (

0 commit comments

Comments
 (0)