Skip to content

Fixes #8280 #8286

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
Feb 12, 2020
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
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3780,22 +3780,22 @@ object Types {

def tryCompiletimeConstantFold(implicit ctx: Context): Type = tycon match {
case tycon: TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) =>
def constValue(tp: Type): Option[Any] = tp match {
def constValue(tp: Type): Option[Any] = tp.dealias match {
case ConstantType(Constant(n)) => Some(n)
case _ => None
}

def boolValue(tp: Type): Option[Boolean] = tp match {
def boolValue(tp: Type): Option[Boolean] = tp.dealias match {
case ConstantType(Constant(n: Boolean)) => Some(n)
case _ => None
}

def intValue(tp: Type): Option[Int] = tp match {
def intValue(tp: Type): Option[Int] = tp.dealias match {
case ConstantType(Constant(n: Int)) => Some(n)
case _ => None
}

def stringValue(tp: Type): Option[String] = tp match {
def stringValue(tp: Type): Option[String] = tp.dealias match {
case ConstantType(Constant(n: String)) => Some(n)
case _ => None
}
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/singleton-ops-test-issue-8280.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import scala.compiletime.ops.int._
import scala.compiletime.S

class Foo[T <: Int] {
def incP = new Foo[T + 1]
def incS = new Foo[S[T]]
}
object Foo {
def apply[T <: Int & Singleton](value : T) : Foo[T] = new Foo[T]
}

val fincS : Foo[2] = Foo(1).incS
val fincP1 : Foo[2] = Foo(1).incP
val fincP2a = Foo(1).incP
val fincP2b : Foo[2] = fincP2a
val fincP3 : Foo[2] = (new Foo[1]).incP