Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1265 from scalamacros/ticket/6318
SI-6318 fixes ClassTag.unapply for primitives
- Loading branch information
Showing
5 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Some(X) | ||
true | ||
Some(X) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import scala.reflect.{ClassTag, classTag} | ||
|
||
object Test extends App { | ||
def test[T: ClassTag](x: T) { | ||
println(classTag[T].runtimeClass.isAssignableFrom(x.getClass)) | ||
println(classTag[T].unapply(x)) | ||
} | ||
|
||
class X(val x: Int) extends AnyVal { override def toString = "X" } | ||
val x = new X(1) | ||
// the commented line crashes because of SI-6326 | ||
//println(classTag[X].runtimeClass.isAssignableFrom(x.getClass)) | ||
println(classTag[X].unapply(x)) | ||
test(x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
true | ||
Some(1) | ||
false | ||
None | ||
true | ||
Some(1) | ||
false | ||
None | ||
true | ||
Some() | ||
false | ||
None | ||
true | ||
Some(1) | ||
false | ||
None | ||
true | ||
Some(1) | ||
false | ||
None | ||
true | ||
Some(1.0) | ||
false | ||
None | ||
true | ||
Some(1.0) | ||
false | ||
None | ||
true | ||
Some(true) | ||
false | ||
None | ||
true | ||
Some(()) | ||
false | ||
None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import scala.reflect.{ClassTag, classTag} | ||
|
||
object Test extends App { | ||
def test[T: ClassTag](x: T) { | ||
println(classTag[T].runtimeClass.isAssignableFrom(x.getClass)) | ||
println(classTag[T].unapply(x)) | ||
} | ||
|
||
{ | ||
val x = 1.toByte | ||
println(ClassTag.Byte.runtimeClass.isAssignableFrom(x.getClass)) | ||
println(ClassTag.Byte.unapply(x)) | ||
test(x) | ||
} | ||
|
||
{ | ||
val x = 1.toShort | ||
println(ClassTag.Short.runtimeClass.isAssignableFrom(x.getClass)) | ||
println(ClassTag.Short.unapply(x)) | ||
test(x) | ||
} | ||
|
||
{ | ||
val x = 1.toChar | ||
println(ClassTag.Char.runtimeClass.isAssignableFrom(x.getClass)) | ||
println(ClassTag.Char.unapply(x)) | ||
test(x) | ||
} | ||
|
||
{ | ||
val x = 1.toInt | ||
println(ClassTag.Int.runtimeClass.isAssignableFrom(x.getClass)) | ||
println(ClassTag.Int.unapply(x)) | ||
test(x) | ||
} | ||
|
||
{ | ||
val x = 1.toLong | ||
println(ClassTag.Long.runtimeClass.isAssignableFrom(x.getClass)) | ||
println(ClassTag.Long.unapply(x)) | ||
test(x) | ||
} | ||
|
||
{ | ||
val x = 1.toFloat | ||
println(ClassTag.Float.runtimeClass.isAssignableFrom(x.getClass)) | ||
println(ClassTag.Float.unapply(x)) | ||
test(x) | ||
} | ||
|
||
{ | ||
val x = 1.toDouble | ||
println(ClassTag.Double.runtimeClass.isAssignableFrom(x.getClass)) | ||
println(ClassTag.Double.unapply(x)) | ||
test(x) | ||
} | ||
|
||
{ | ||
val x = true | ||
println(ClassTag.Boolean.runtimeClass.isAssignableFrom(x.getClass)) | ||
println(ClassTag.Boolean.unapply(x)) | ||
test(x) | ||
} | ||
|
||
{ | ||
val x = () | ||
println(ClassTag.Unit.runtimeClass.isAssignableFrom(x.getClass)) | ||
println(ClassTag.Unit.unapply(x)) | ||
test(x) | ||
} | ||
} |