diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-10-28 13:44:10 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-10-28 23:17:48 +0100 |
commit | 74297159f5c4df42dcf6289f4daea79e7d4f7bb4 (patch) | |
tree | 3ab72667fcf8689ba01fb7272601965dcdc25153 /src/compiler | |
parent | 2c554249fd8e99286134b217027b6e3cb2c92d77 (diff) | |
download | scala-74297159f5c4df42dcf6289f4daea79e7d4f7bb4.tar.gz scala-74297159f5c4df42dcf6289f4daea79e7d4f7bb4.tar.bz2 scala-74297159f5c4df42dcf6289f4daea79e7d4f7bb4.zip |
SI-6575 Plug inference leak of AbstractPartialFun
Usually this isn't needed, as partial functions can only be
defined with an expected type. But if that expected type is
and inherited method return type, the actual type of the partial
function literal is used, and the implementation detail of
`AbstractPartialFunction[A, B] with Serializable` leaks out.
After this change, the inferred types match those from
Scala 2.9.2.
ticket/6575 ~/code/scala scalac29 -Xprint:typer test/files/pos/t6575a.scala | grep def > 29.txt
ticket/6575 ~/code/scala squalac -Xprint:typer test/files/pos/t6575a.scala | grep def > 210.txt
ticket/6575 ~/code/scala diff -u 29.txt 210.txt
--- 29.txt 2012-10-28 13:51:07.000000000 +0100
+++ 210.txt 2012-10-28 13:51:20.000000000 +0100
@@ -1,7 +1,16 @@
def foo: PartialFunction[Int,Int]
def /*Y*/$init$(): Unit = {
- absoverride def foo: PartialFunction[Int,Int] = ((x0$1: Int) => x0$1 match {
+ absoverride def foo: PartialFunction[Int,Int] = {
+ def <init>(): anonymous class $anonfun = {
+ final override def applyOrElse[A1 >: Nothing <: Int, B1 >: Int <: Any](x$1: A1, default: A1 => B1): B1 = (x$1: A1 @unchecked) match {
+ final def isDefinedAt(x$1: Int): Boolean = (x$1: Int @unchecked) match {
def /*Z*/$init$(): Unit = {
- absoverride def foo: PartialFunction[Int,Int] = ((x0$2: Int) => x0$2 match {
+ absoverride def foo: PartialFunction[Int,Int] = {
+ def <init>(): anonymous class $anonfun = {
+ final override def applyOrElse[A1 >: Nothing <: Int, B1 >: Int <: Any](x$1: A1, default: A1 => B1): B1 = (x$1: A1 @unchecked) match {
+ final def isDefinedAt(x$1: Int): Boolean = (x$1: Int @unchecked) match {
def /*Comb*/$init$(): Unit = {
- absoverride def foo: PartialFunction[Int,Int] = ((x0$3: Int) => x0$3 match {
+ absoverride def foo: PartialFunction[Int,Int] = {
+ def <init>(): anonymous class $anonfun = {
+ final override def applyOrElse[A1 >: Nothing <: Int, B1 >: Int <: Any](x$1: A1, default: A1 => B1): B1 = (x$1: A1 @unchecked) match {
+ final def isDefinedAt(x$1: Int): Boolean = (x$1: Int @unchecked) match {
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index f82786da35..8e06588ed8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2590,7 +2590,15 @@ trait Typers extends Modes with Adaptations with Tags { def translated = if (members.head eq EmptyTree) setError(tree) - else typed(atPos(tree.pos)(Block(List(ClassDef(anonClass, NoMods, ListOfNil, ListOfNil, members, tree.pos.focus)), atPos(tree.pos.focus)(New(anonClass.tpe)))), mode, pt) + else { + val typedBlock = typed(atPos(tree.pos)( + Block(ClassDef(anonClass, NoMods, ListOfNil, ListOfNil, members, tree.pos.focus), atPos(tree.pos.focus)(New(anonClass.tpe))) + ), mode, pt) + // Don't leak implementation details into the type, see SI-6575 + if (isPartial && !typedBlock.isErrorTyped) + typedBlock modifyType (_ baseType PartialFunctionClass) + else typedBlock + } } // Function(params, Match(sel, cases)) ==> new <Partial>Function { def apply<OrElse>(params) = `translateMatch('sel match { cases }')` } |