summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-10-03 10:52:28 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-10-03 10:52:28 -0700
commit63999cd7d61482ab2fdd17d37ffa6db323f5f84d (patch)
tree29a9ddae826a2ff6c7621b19d5cc63bcdba82055
parentb37336510f7f2aab50ab4827fc3d762745ef18d8 (diff)
parentb090f9748fff915df82f2a4908e7075f5cf1c91c (diff)
downloadscala-63999cd7d61482ab2fdd17d37ffa6db323f5f84d.tar.gz
scala-63999cd7d61482ab2fdd17d37ffa6db323f5f84d.tar.bz2
scala-63999cd7d61482ab2fdd17d37ffa6db323f5f84d.zip
Merge pull request #3013 from retronym/topic/unspec-fix-windows
Rework cff8b569 to heal the windows build.
-rw-r--r--src/reflect/scala/reflect/internal/Names.scala6
-rw-r--r--src/reflect/scala/reflect/internal/StdNames.scala30
-rw-r--r--test/files/run/global-showdef.scala2
-rw-r--r--test/junit/scala/tools/nsc/symtab/StdNamesTest.scala8
4 files changed, 22 insertions, 24 deletions
diff --git a/src/reflect/scala/reflect/internal/Names.scala b/src/reflect/scala/reflect/internal/Names.scala
index f998d95349..4075653674 100644
--- a/src/reflect/scala/reflect/internal/Names.scala
+++ b/src/reflect/scala/reflect/internal/Names.scala
@@ -87,11 +87,13 @@ trait Names extends api.Names {
* TODO - have a mode where name validation is performed at creation time
* (e.g. if a name has the string "$class" in it, then fail if that
* string is not at the very end.)
+ *
+ * @param len0 the length of the name. Negative lengths result in empty names.
*/
- final def newTermName(cs: Array[Char], offset: Int, len: Int, cachedString: String): TermName = {
+ final def newTermName(cs: Array[Char], offset: Int, len0: 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 len = math.max(len0, 0)
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 0aee71c26e..af26253802 100644
--- a/src/reflect/scala/reflect/internal/StdNames.scala
+++ b/src/reflect/scala/reflect/internal/StdNames.scala
@@ -407,11 +407,8 @@ trait StdNames {
*/
def unspecializedName(name: Name): Name = (
// 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)
- }
+ if (name endsWith SPECIALIZED_SUFFIX)
+ name.subName(0, name.lastIndexOf('m') - 1)
else name
)
@@ -426,19 +423,18 @@ trait StdNames {
*
* @return (unspecializedName, class tparam specializations, method tparam specializations)
*/
- def splitSpecializedName(name: Name): (Name, String, String) = {
+ 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, "", "")
- }
+ 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, "", "")
// Nominally, name$default$N, encoded for <init>
def defaultGetterName(name: Name, pos: Int): TermName = (
diff --git a/test/files/run/global-showdef.scala b/test/files/run/global-showdef.scala
index 0dbaba979d..c3ace590ed 100644
--- a/test/files/run/global-showdef.scala
+++ b/test/files/run/global-showdef.scala
@@ -54,7 +54,7 @@ object Bippy {
val run = new compiler.Run()
run.compileSources(List(src))
}
- (output split "\\n").toList
+ output.linesIterator.toList
}
def showClass(name: String) = lines("-Yshow:typer", "-Xshow-class", name)
def showObject(name: String) = lines("-Yshow:typer", "-Xshow-object", name)
diff --git a/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala b/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala
index 05e69978c6..4a39cf9d48 100644
--- a/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala
+++ b/test/junit/scala/tools/nsc/symtab/StdNamesTest.scala
@@ -28,8 +28,8 @@ class StdNamesTest {
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(nme.EMPTY, TermName(s"T1$SPECIALIZED_SUFFIX"))
+ test(nme.EMPTY, SPECIALIZED_SUFFIX)
}
@Test
@@ -40,7 +40,7 @@ class StdNamesTest {
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)
+ test((nme.EMPTY, "T1", ""), TermName(s"T1$SPECIALIZED_SUFFIX"))
+ test((nme.EMPTY, "", ""), SPECIALIZED_SUFFIX)
}
}