From bcf6354220dd4f4700dc7aec47b54ab0bc9d1798 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 8 Jul 2016 15:28:37 +0200 Subject: Fix: #1366, constant adaptation Fix: #1366. Constant adaptation did not work if the expected type was an as yet uninstantiated type variable. --- src/dotty/tools/dotc/core/Constants.scala | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/dotty/tools/dotc/core/Constants.scala') diff --git a/src/dotty/tools/dotc/core/Constants.scala b/src/dotty/tools/dotc/core/Constants.scala index e13e07f58..0f8c68bad 100644 --- a/src/dotty/tools/dotc/core/Constants.scala +++ b/src/dotty/tools/dotc/core/Constants.scala @@ -167,12 +167,19 @@ object Constants { /** Convert constant value to conform to given type. */ def convertTo(pt: Type)(implicit ctx: Context): Constant = { - def lowerBound(pt: Type): Type = pt.dealias.stripTypeVar match { - case tref: TypeRef if !tref.symbol.isClass => lowerBound(tref.info.bounds.lo) - case param: PolyParam => lowerBound(ctx.typerState.constraint.nonParamBounds(param).lo) + def classBound(pt: Type): Type = pt.dealias.stripTypeVar match { + case tref: TypeRef if !tref.symbol.isClass => classBound(tref.info.bounds.lo) + case param: PolyParam => + ctx.typerState.constraint.entry(param) match { + case TypeBounds(lo, hi) => + if (hi.classSymbol.isPrimitiveValueClass) hi //constrain further with high bound + else lo + case NoType => param.binder.paramBounds(param.paramNum).lo + case inst => classBound(inst) + } case pt => pt } - val target = lowerBound(pt).typeSymbol + val target = classBound(pt).typeSymbol if (target == tpe.typeSymbol) this else if ((target == defn.ByteClass) && isByteRange) -- cgit v1.2.3