Skip to content

Commit

Permalink
Merge pull request #1240 from joroKr21/witness-refinement
Browse files Browse the repository at this point in the history
Remove refinement from Witness.value
  • Loading branch information
joroKr21 authored Jul 20, 2022
2 parents f0e443b + 8b7f95d commit 654fe58
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
18 changes: 18 additions & 0 deletions core/jvm/src/test/scala/shapeless/witness.scala
Original file line number Diff line number Diff line change
@@ -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")
}
}
2 changes: 1 addition & 1 deletion core/src/main/scala/shapeless/singletons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions core/src/test/scala/shapeless/singletons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down

0 comments on commit 654fe58

Please # to comment.