diff --git a/src/dotty/tools/dotc/core/Constants.scala b/src/dotty/tools/dotc/core/Constants.scala index e13e07f5881b..0f8c68bad4bf 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) diff --git a/tests/pos/i1366.scala b/tests/pos/i1366.scala new file mode 100644 index 000000000000..b75af68b1526 --- /dev/null +++ b/tests/pos/i1366.scala @@ -0,0 +1,6 @@ +object Test { + + val a: Char = 98 + val c: (Char, Char) = ('a', 98) + +}