Skip to content

Commit

Permalink
Remove final modifier check when unboxing AnyVal Products during rewr…
Browse files Browse the repository at this point in the history
…iting

This check doesn?t work on Scala 2.10 due to the bug that is addressed by the following change:

scala/scala#2636

The change wasn?t back-ported to 2.10 due to binary compatibility concerns. So we now don?t
require a value that is being unboxed to be of a final class. This should be ok since we only
unbox when a primitive argument type is expected which (we think) should only happen if
the argument is an AnyVal.
  • Loading branch information
inkytonik committed Apr 27, 2017
1 parent ea11a82 commit 9f7787f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ trait RewriterCore {
import com.google.common.base.Function
import com.google.common.cache.{CacheBuilder, CacheLoader}
import java.lang.{Class, IllegalArgumentException, NoSuchFieldException}
import java.lang.reflect.{Constructor, Modifier}
import java.lang.reflect.Constructor

type Duper = (Any, Array[AnyRef]) => Any

Expand Down Expand Up @@ -462,15 +462,13 @@ trait RewriterCore {
newChildren
}

def unboxAnyVal(s : AnyRef) : AnyRef = {
val klass = s.getClass
def unboxAnyVal(s : AnyRef) : AnyRef =
s match {
case p : Product if Modifier.isFinal(klass.getModifiers) && p.productArity == 1 =>
case p : Product if p.productArity == 1 =>
p.productElement(0).asInstanceOf[AnyRef]
case _ =>
s
}
}

}

Expand Down
2 changes: 2 additions & 0 deletions notes/2.1.0.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This is a simplification, enhancement and bug fix release cross-published for Sc

### Bug Fixes

* `Rewriter`: structures that contain case classes that extend `AnyVal` are now rewritten correctly by unboxing the value where necessary.

* Handling of source file paths should now work properly on Windows (contributed by Matt Pigram).
* `Source.dropPrefix`:
** Avoid separator bug when dropping filename prefixes when there is no prefix.
Expand Down

0 comments on commit 9f7787f

Please sign in to comment.