Skip to content

Commit f68aad8

Browse files
committed
SIP-23 widen LiteralType in result type
1 parent d71cd1c commit f68aad8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ trait Namers extends MethodSynthesis {
871871
private def widenIfNecessary(sym: Symbol, tpe: Type, pt: Type): Type = {
872872
// Are we inferring the result type of a stable symbol, whose type doesn't refer to a hidden symbol?
873873
// If we refer to an inaccessible symbol, let's hope widening will result in an expressible type.
874-
val mayKeepSingletonType = sym.isStable && !refersToSymbolLessAccessibleThan(tpe, sym)
874+
// (A LiteralType should be widened because it's too precise for a definition's type.)
875+
val mayKeepSingletonType = !tpe.isInstanceOf[LiteralType] && sym.isStable && !refersToSymbolLessAccessibleThan(tpe, sym)
875876

876877
// Only final vals may be constant folded, so deconst inferred type of other members.
877878
@inline def keepSingleton = if (sym.isFinal) tpe else tpe.deconst

0 commit comments

Comments
 (0)