summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/internal/Names.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-09-16 11:12:13 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-09-16 16:44:28 +0200
commitcff8b569c39fb2ce57157fa6adf4ab9289721033 (patch)
tree793273d29da6141bc7b4414a82a5d59c6a2f44fb /src/reflect/scala/reflect/internal/Names.scala
parent4aad4eb6c1f10abd64ec5dfd8eeba091491349e2 (diff)
downloadscala-cff8b569c39fb2ce57157fa6adf4ab9289721033.tar.gz
scala-cff8b569c39fb2ce57157fa6adf4ab9289721033.tar.bz2
scala-cff8b569c39fb2ce57157fa6adf4ab9289721033.zip
SI-7841 More robust unspecialization of names
Names like `T1$sp`, which can arise from `AnyRef` specialization, were leading to negative length Names if they ever passed through `unspecializedName` or `splitSpecializedName`. This code path was touched when printing the tree of a certain AnyRef specialized classes after specialization, such as `AbstractPartialFunction` (which had such specialization until a few commits ago.) This commit handles that case correctly, and generally hardens against unexpected names, which could pop up from third party classes. The documentation for `splitSpecializedName` transposed the class and method specializations. The things you discover when you turn examples in documentation in to test cases! In addition, we now require non-negative length and offset in `newTermName`
Diffstat (limited to 'src/reflect/scala/reflect/internal/Names.scala')
-rw-r--r--src/reflect/scala/reflect/internal/Names.scala2
1 files changed, 2 insertions, 0 deletions
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)))