Skip to content

Commit

Permalink
Merge pull request #1242 from joroKr21/witness-refinement-backport
Browse files Browse the repository at this point in the history
Remove refinement from Witness.value
  • Loading branch information
joroKr21 authored Feb 11, 2022
2 parents 833a6a4 + 8456f37 commit 0a08460
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 @@ -31,7 +31,7 @@ import scala.util.Try
*/
trait Witness extends Serializable {
type T
val value: T {}
val value: T
}

object Witness extends Dynamic {
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 @@ -589,6 +589,15 @@ class SingletonTypesTests {
assertTypedEquals[ObjectThis.type](ObjectThis.w1.value, ObjectThis.w2.value)
}

@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 0a08460

Please sign in to comment.