forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix generation of derived value classes wrapping Unit, Null, and Noth…
…ing. All sorts o' specialness going on here. Unit morphs into a BoxedUnit when it's in a field, but void when it's the return type of a method, which is expected. This means, though, that the unboxing method of a Unit-wrapping value class has the signature `()V`, not `()Lscala/runtime/BoxedUnit`, so attempting to use its value in the equals method spits out some wonderful invalid bytecode, instead. Similar sadness occurs for Nothing and Null as well. The "solution" is to not even bother to check for equality, as we've only got at most one legitimate value of each of these types. Because the code is shared with `case class`es, this also changes the bytecode we generate for them. Obviously this is an "unrelated change" as far as the bugs this is meant to fix go, but it's innocuous enough as far as I can tell. I also slipped a constructor call into the generated `ClassCastException` that gets thrown when we are asked to emit a cast for a primitive type in `BCodeBodyBuilder`, so we generate valid bytecode if we ever wind in that branch. Discussion on scala#5938 implies that this branch shouldn't ever be reached, so add a devWarning now that it doesn't cause an obvious error. Fixes scala/bug#9240 Fixes scala/bug#10361
- Loading branch information
Showing
5 changed files
with
52 additions
and
9 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 @@ | ||
-Xverify |
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,20 @@ | ||
// scala/bug#10361 | ||
final class AnyValNothing(val self: Nothing) extends AnyVal | ||
final class AnyValNull (val self: Null ) extends AnyVal | ||
// scala/bug#9240 | ||
final class AnyValUnit (val self: Unit ) extends AnyVal | ||
|
||
object Test extends App { | ||
def avn = new AnyValNull(null) | ||
assert(avn == avn) | ||
/*this throws NPE right now b/c scala/bug#7396 */ | ||
//assert(avn.hashCode() == 0) | ||
|
||
def avu = new AnyValUnit(()) | ||
assert((avu.self: Any).equals(())) | ||
assert(avu equals avu) | ||
assert((avu: Any).## == 0) | ||
|
||
/* can't really test AnyValNothing, but summon it so it gets verified */ | ||
AnyValNothing.toString | ||
} |