Skip to content

Commit 6ca5b9d

Browse files
Merge pull request #1371 from dotty-staging/fix-#1366
Fix #1366: constant adaptation
2 parents 1719178 + ed697f5 commit 6ca5b9d

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-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)

tests/pos/i1366.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
3+
val a: Char = 98
4+
val c: (Char, Char) = ('a', 98)
5+
6+
}

0 commit comments

Comments
 (0)