diff options
-rw-r--r-- | src/build/genprod.scala | 4 | ||||
-rw-r--r-- | src/library/scala/Function0.scala | 2 | ||||
-rw-r--r-- | src/library/scala/Function1.scala | 2 | ||||
-rw-r--r-- | src/library/scala/runtime/AbstractFunction1.scala | 2 | ||||
-rw-r--r-- | src/library/scala/runtime/AbstractPartialFunction.scala | 14 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Names.scala | 2 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/StdNames.scala | 39 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/symtab/StdNamesTest.scala | 46 |
8 files changed, 91 insertions, 20 deletions
diff --git a/src/build/genprod.scala b/src/build/genprod.scala index cd01363cb6..ed436fe2e4 100644 --- a/src/build/genprod.scala +++ b/src/build/genprod.scala @@ -113,8 +113,8 @@ object FunctionZero extends Function(0) { object FunctionOne extends Function(1) { override def classAnnotation = "@annotation.implicitNotFound(msg = \"No implicit view available from ${T1} => ${R}.\")\n" - override def contravariantSpecs = "@specialized(scala.Int, scala.Long, scala.Float, scala.Double/*, scala.AnyRef*/) " - override def covariantSpecs = "@specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double/*, scala.AnyRef*/) " + override def contravariantSpecs = "@specialized(scala.Int, scala.Long, scala.Float, scala.Double) " + override def covariantSpecs = "@specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double) " override def descriptiveComment = " " + functionNTemplate.format("succ", "anonfun1", """ diff --git a/src/library/scala/Function0.scala b/src/library/scala/Function0.scala index 54cba021e0..e13aaad7bc 100644 --- a/src/library/scala/Function0.scala +++ b/src/library/scala/Function0.scala @@ -6,7 +6,7 @@ ** |/ ** \* */ // GENERATED CODE: DO NOT EDIT. -// genprod generated these sources at: Sun Mar 24 14:14:12 CET 2013 +// genprod generated these sources at: Sun Sep 15 20:42:00 CEST 2013 package scala diff --git a/src/library/scala/Function1.scala b/src/library/scala/Function1.scala index 2e3de54c5a..620dcc19aa 100644 --- a/src/library/scala/Function1.scala +++ b/src/library/scala/Function1.scala @@ -32,7 +32,7 @@ package scala */ @annotation.implicitNotFound(msg = "No implicit view available from ${T1} => ${R}.") -trait Function1[@specialized(scala.Int, scala.Long, scala.Float, scala.Double/*, scala.AnyRef*/) -T1, @specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double/*, scala.AnyRef*/) +R] extends AnyRef { self => +trait Function1[@specialized(scala.Int, scala.Long, scala.Float, scala.Double) -T1, @specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double) +R] extends AnyRef { self => /** Apply the body of this function to the argument. * @return the result of function application. */ diff --git a/src/library/scala/runtime/AbstractFunction1.scala b/src/library/scala/runtime/AbstractFunction1.scala index 8d68017a6f..178280cb46 100644 --- a/src/library/scala/runtime/AbstractFunction1.scala +++ b/src/library/scala/runtime/AbstractFunction1.scala @@ -9,6 +9,6 @@ package scala.runtime -abstract class AbstractFunction1[@specialized(scala.Int, scala.Long, scala.Float, scala.Double/*, scala.AnyRef*/) -T1, @specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double/*, scala.AnyRef*/) +R] extends Function1[T1, R] { +abstract class AbstractFunction1[@specialized(scala.Int, scala.Long, scala.Float, scala.Double) -T1, @specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double) +R] extends Function1[T1, R] { } diff --git a/src/library/scala/runtime/AbstractPartialFunction.scala b/src/library/scala/runtime/AbstractPartialFunction.scala index e3516bc4d9..7129f22f60 100644 --- a/src/library/scala/runtime/AbstractPartialFunction.scala +++ b/src/library/scala/runtime/AbstractPartialFunction.scala @@ -25,7 +25,7 @@ import scala.annotation.unspecialized * @author Pavel Pavlov * @since 2.10 */ -abstract class AbstractPartialFunction[@specialized(scala.Int, scala.Long, scala.Float, scala.Double, scala.AnyRef) -T1, @specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double, scala.AnyRef) +R] extends Function1[T1, R] with PartialFunction[T1, R] { self => +abstract class AbstractPartialFunction[@specialized(scala.Int, scala.Long, scala.Float, scala.Double) -T1, @specialized(scala.Unit, scala.Boolean, scala.Int, scala.Float, scala.Long, scala.Double) +R] extends Function1[T1, R] with PartialFunction[T1, R] { self => // this method must be overridden for better performance, // for backwards compatibility, fall back to the one inherited from PartialFunction // this assumes the old-school partial functions override the apply method, though @@ -35,3 +35,15 @@ abstract class AbstractPartialFunction[@specialized(scala.Int, scala.Long, scala // let's not make it final so as not to confuse anyone /*final*/ def apply(x: T1): R = applyOrElse(x, PartialFunction.empty) } + +// Manual stand-ins for formerly specialized variations. +// Not comprehensive, only sufficent to run scala-check built scala 2.11.0-M5 +// TODO Scala 2.10.0.M6 Remove this once scalacheck is published against M6. +private[runtime] abstract class AbstractPartialFunction$mcIL$sp extends scala.runtime.AbstractPartialFunction[Any, Int] { + override def apply(x: Any): Int = apply$mcIL$sp(x) + def apply$mcIL$sp(x: Any): Int = applyOrElse(x, PartialFunction.empty) +} +private[runtime] abstract class AbstractPartialFunction$mcFL$sp extends scala.runtime.AbstractPartialFunction[Any, Float] { + override def apply(x: Any): Float = apply$mcIL$sp(x) + def apply$mcIL$sp(x: Any): Float = applyOrElse(x, PartialFunction.empty) +} diff --git a/src/reflect/scala/reflect/internal/Names.scala b/src/reflect/scala/reflect/internal/Names.scala index ed248d6e1e..f998d95349 100644 --- a/src/reflect/scala/reflect/internal/Names.scala +++ b/src/reflect/scala/reflect/internal/Names.scala @@ -90,6 +90,8 @@ trait Names extends api.Names { */ final def newTermName(cs: Array[Char], offset: Int, len: Int, cachedString: String): TermName = { def body = { + require(offset >= 0, "offset must be non-negative, got " + offset) + require(len >= 0, "length must be non-negative, got " + len) val h = hashValue(cs, offset, len) & HASH_MASK var n = termHashtable(h) while ((n ne null) && (n.length != len || !equals(n.start, cs, offset, len))) diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index 686ebf5a1e..6407a3979c 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -413,32 +413,43 @@ trait StdNames { @deprecated("Use Name#getterName", "2.11.0") def getterName(name: TermName): TermName = name.getterName @deprecated("Use Name#getterName", "2.11.0") def setterToGetter(name: TermName): TermName = name.getterName + /** + * Convert `Tuple2$mcII` to `Tuple2`, or `T1$sp` to `T1`. + */ def unspecializedName(name: Name): Name = ( - if (name endsWith SPECIALIZED_SUFFIX) - name.subName(0, name.lastIndexOf('m') - 1) + // DUPLICATED LOGIC WITH `splitSpecializedName` + if (name endsWith SPECIALIZED_SUFFIX) { + val idxM = name.lastIndexOf('m') + val to = (if (idxM > 0) idxM - 1 else name.length - SPECIALIZED_SUFFIX.length) + name.subName(0, to) + } else name ) /** Return the original name and the types on which this name * is specialized. For example, * {{{ - * splitSpecializedName("foo$mIcD$sp") == ('foo', "I", "D") + * splitSpecializedName("foo$mIcD$sp") == ('foo', "D", "I") * }}} * `foo$mIcD$sp` is the name of a method specialized on two type * parameters, the first one belonging to the method itself, on Int, * and another one belonging to the enclosing class, on Double. + * + * @return (unspecializedName, class tparam specializations, method tparam specializations) */ - def splitSpecializedName(name: Name): (Name, String, String) = - if (name endsWith SPECIALIZED_SUFFIX) { - val name1 = name dropRight SPECIALIZED_SUFFIX.length - val idxC = name1 lastIndexOf 'c' - val idxM = name1 lastIndexOf 'm' - - (name1.subName(0, idxM - 1), - name1.subName(idxC + 1, name1.length).toString, - name1.subName(idxM + 1, idxC).toString) - } else - (name, "", "") + def splitSpecializedName(name: Name): (Name, String, String) = { + // DUPLICATED LOGIC WITH `unspecializedName` + if (name endsWith SPECIALIZED_SUFFIX) { + val name1 = name dropRight SPECIALIZED_SUFFIX.length + val idxC = name1 lastIndexOf 'c' + val idxM = name1 lastIndexOf 'm' + if (idxC > idxM && idxM > 0) + (name1.subName(0, idxM - 1), name1.subName(idxC + 1, name1.length).toString, name1.subName(idxM + 1, idxC).toString) + else + (name.subName(0, name.length - SPECIALIZED_SUFFIX.length), "", "") + } + else (name, "", "") + } // Nominally, name$default$N, encoded for <init> def defaultGetterName(name: Name, pos: Int): TermName = ( diff --git a/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala b/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala new file mode 100644 index 0000000000..05e69978c6 --- /dev/null +++ b/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala @@ -0,0 +1,46 @@ +package scala.tools.nsc +package symtab + +import org.junit.Assert._ +import scala.tools.testing.AssertUtil._ +import org.junit.{Ignore, Test} +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class StdNamesTest { + object symbolTable extends SymbolTableForUnitTesting + import symbolTable._ + import nme.{SPECIALIZED_SUFFIX, unspecializedName, splitSpecializedName} + + @Test + def testNewTermNameInvalid(): Unit = { + assertThrows[IllegalArgumentException](newTermName("foo".toCharArray, 0, -1)) + assertThrows[IllegalArgumentException](newTermName("foo".toCharArray, 0, 0)) + assertThrows[IllegalArgumentException](newTermName("foo".toCharArray, -1, 1)) + } + + @Test + def testUnspecializedName(): Unit = { + def test(expected: Name, nme: Name) { + assertEquals(expected, unspecializedName(nme)) + } + test(TermName("Tuple2"), TermName("Tuple2$mcII" + SPECIALIZED_SUFFIX)) + test(TermName("foo"), TermName("foo$mIcD" + SPECIALIZED_SUFFIX)) + test(TermName("foo"), TermName("foo$mIc" + SPECIALIZED_SUFFIX)) + test(TermName("T1"), TermName(s"T1$SPECIALIZED_SUFFIX")) + test(TermName(""), SPECIALIZED_SUFFIX) + } + + @Test + def testSplitSpecializedName(): Unit = { + def test(expected: (Name, String, String), nme: Name) { + assertEquals(expected, splitSpecializedName(nme)) + } + test((TermName("Tuple2"), "II", ""), TermName("Tuple2$mcII" + SPECIALIZED_SUFFIX)) + test((TermName("foo"), "D", "I"), TermName("foo$mIcD" + SPECIALIZED_SUFFIX)) + test((TermName("foo"), "", "I"), TermName("foo$mIc" + SPECIALIZED_SUFFIX)) + test((TermName("T1"), "", ""), TermName(s"T1$SPECIALIZED_SUFFIX")) + test((TermName(""), "", ""), SPECIALIZED_SUFFIX) + } +} |