diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index b1412318c2de..1f23faa69fd5 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -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 } diff --git a/tests/pos/singleton-ops-test-issue-8280.scala b/tests/pos/singleton-ops-test-issue-8280.scala new file mode 100644 index 000000000000..fd5a0ef54717 --- /dev/null +++ b/tests/pos/singleton-ops-test-issue-8280.scala @@ -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