Skip to content

Commit bcf6354

Browse files
committed
Fix: scala#1366, constant adaptation
Fix: scala#1366. Constant adaptation did not work if the expected type was an as yet uninstantiated type variable.
1 parent 07fd8a3 commit bcf6354

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/dotty/tools/dotc/core/Constants.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,19 @@ object Constants {
167167
/** Convert constant value to conform to given type.
168168
*/
169169
def convertTo(pt: Type)(implicit ctx: Context): Constant = {
170-
def lowerBound(pt: Type): Type = pt.dealias.stripTypeVar match {
171-
case tref: TypeRef if !tref.symbol.isClass => lowerBound(tref.info.bounds.lo)
172-
case param: PolyParam => lowerBound(ctx.typerState.constraint.nonParamBounds(param).lo)
170+
def classBound(pt: Type): Type = pt.dealias.stripTypeVar match {
171+
case tref: TypeRef if !tref.symbol.isClass => classBound(tref.info.bounds.lo)
172+
case param: PolyParam =>
173+
ctx.typerState.constraint.entry(param) match {
174+
case TypeBounds(lo, hi) =>
175+
if (hi.classSymbol.isPrimitiveValueClass) hi //constrain further with high bound
176+
else lo
177+
case NoType => param.binder.paramBounds(param.paramNum).lo
178+
case inst => classBound(inst)
179+
}
173180
case pt => pt
174181
}
175-
val target = lowerBound(pt).typeSymbol
182+
val target = classBound(pt).typeSymbol
176183
if (target == tpe.typeSymbol)
177184
this
178185
else if ((target == defn.ByteClass) && isByteRange)

0 commit comments

Comments
 (0)