Skip to content

Document that AnyVal "box" and "unbox" are implemented by BoxesRunTime #6898

@scabug

Description

@scabug

As discussed in #6710 and on scala-lang [1], the "box" and "unbox" methods of AnyVal classes (except Unit) are not actually implemented by the code in AnyVal [2].

Instead, the real implementation comes from BoxesRunTime (e.g. [3]). This is functionally different, creating potential for confusion.

As per the scala-lang discussion and #6710, changing the AnyVal code itself would have too much potential impact and thus be too risky. Documenting the behaviour would be a safer option.

From Paul Phillips' comment:

"If we're not using it in generated code and don't intend to, the ideal change is probably to deprecate it and then remove it. Next best (and to do regardless) is to document the behavior and the fact that it isn't actually used by the compiler." [4]

Source code of AnyVal classes and screenshots of documentation after

ant all.clean
ant build
./tools/codegen-anyvals
ANT_OPTS="-Xms512M -Xmx1024M -Xss1M -XX:MaxPermSize=128M" ant docs

attached.

[1] https://groups.google.com/d/topic/scala-language/kBQnJ3XuKeM/discussion
[2] https://github.com/scala/scala/blob/master/src/compiler/scala/tools/cmd/gen/AnyVals.scala#L2321
[3] https://github.com/scala/scala/blob/master/src/library/scala/runtime/BoxesRunTime.java#L87
[4] https://groups.google.com/d/msg/scala-language/kBQnJ3XuKeM/qvLnORIiXqAJ

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions