Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Value classes: eliminated half-boxing
We now apply erasure of value classes everywhere. previously, erasure was disabled in the value class itself. This led to irregegularities and bugs. See test run/valueclasses-pavlov.scala for something that led to a ClassCastException before.
- Loading branch information
Showing
9 changed files
with
87 additions
and
18 deletions.
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
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,7 @@ | ||
valueclasses-pavlov.scala:8: error: double definition: | ||
method foo:(x: Box2)String and | ||
method foo:(x: String)String at line 7 | ||
have same type after erasure: (x: String)String | ||
def foo(x: Box2) = "foo(Box2): ok" | ||
^ | ||
one error found |
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,23 @@ | ||
trait Foo[T <: AnyVal] extends Any { | ||
def foo(x: String): String | ||
def foo(x: T): String | ||
} | ||
|
||
class Box1(val value: String) extends AnyVal with Foo[Box2] { | ||
def foo(x: String) = "foo(String): ok" | ||
def foo(x: Box2) = "foo(Box2): ok" | ||
} | ||
|
||
class Box2(val value: String) extends AnyVal | ||
|
||
|
||
object test2a { | ||
|
||
def main(args: Array[String]) { | ||
val b1 = new Box1(null) | ||
val b2 = new Box2(null) | ||
val f: Foo[Box2] = b1 | ||
println(f.foo("")) | ||
println(f.foo(b2)) | ||
} | ||
} |
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
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,2 @@ | ||
box1: ok | ||
box2: ok |
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,26 @@ | ||
trait Foo extends Any { | ||
def box1(x: Box1): String | ||
def box2(x: Box2): String | ||
} | ||
|
||
class Box1(val value: String) extends AnyVal | ||
|
||
class Box2(val value: String) extends AnyVal with Foo { | ||
def box1(x: Box1) = "box1: ok" | ||
def box2(x: Box2) = "box2: ok" | ||
} | ||
|
||
class C(x: String) { | ||
def this() = this("") | ||
} | ||
|
||
object Test { | ||
|
||
def main(args: Array[String]) { | ||
val b1 = new Box1("") | ||
val b2 = new Box2("") | ||
val f: Foo = b2 | ||
println(f.box1(b1)) | ||
println(f.box2(b2)) | ||
} | ||
} |