diff --git a/core/jvm/src/test/scala/shapeless/witness.scala b/core/jvm/src/test/scala/shapeless/witness.scala new file mode 100644 index 000000000..e14e298f6 --- /dev/null +++ b/core/jvm/src/test/scala/shapeless/witness.scala @@ -0,0 +1,18 @@ +package shapeless + +import org.junit.Assert._ +import org.junit.Test + +import scala.reflect.runtime.universe.WeakTypeTag + +class WitnessJvmTests { + + @Test + def testRuntimeReflection: Unit = { + val w1: Witness.Lt[Int] = Witness(1) + val v1 = w1.value + def infer[T](v: T)(implicit ev: WeakTypeTag[T]): WeakTypeTag[T] = ev + val tag = infer(v1) + assertEquals(tag.tpe.toString, "w1.T") + } +} diff --git a/core/src/main/scala/shapeless/singletons.scala b/core/src/main/scala/shapeless/singletons.scala index 71ddd4503..aa69376cb 100644 --- a/core/src/main/scala/shapeless/singletons.scala +++ b/core/src/main/scala/shapeless/singletons.scala @@ -28,7 +28,7 @@ import scala.reflect.macros.whitebox */ trait Witness extends Serializable { type T - val value: T {} + val value: T } object Witness extends Dynamic with WitnessInstances { diff --git a/core/src/test/scala/shapeless/singletons.scala b/core/src/test/scala/shapeless/singletons.scala index 1173692ce..fb6481233 100644 --- a/core/src/test/scala/shapeless/singletons.scala +++ b/core/src/test/scala/shapeless/singletons.scala @@ -518,6 +518,15 @@ class SingletonTypesTests { assertTypedEquals[A.type](A1().getT, A) } + @Test + def testTypeInference: Unit = { + val singletonW = Witness(3) + def s3[T](v: T)(implicit ev: Witness.Aux[T]) = v + val v = singletonW.value + val s = s3(v) + assertEquals(s, v) + } + class NestingBug { val o: AnyRef = new Object {}