Skip to content

Fix #1366: constant adaptation #1371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/dotty/tools/dotc/core/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i1366.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Test {

val a: Char = 98
val c: (Char, Char) = ('a', 98)

}