Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove refinement from Witness.value #1242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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