From b5e27c1d2a1acc045a37271a2e492625695ad02f Mon Sep 17 00:00:00 2001 From: Oron Port Date: Tue, 11 Feb 2020 14:11:23 +0200 Subject: [PATCH 1/2] Fixes #8280 --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 } From e44e8f0d7a28d424610a1970edddaf4683720d21 Mon Sep 17 00:00:00 2001 From: Oron Port Date: Tue, 11 Feb 2020 14:14:27 +0200 Subject: [PATCH 2/2] Add test --- tests/pos/singleton-ops-test-issue-8280.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/pos/singleton-ops-test-issue-8280.scala 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