From 2fbd539e353fd9d234f9a633d7606529d871d939 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Thu, 16 Apr 2015 21:56:30 +0200 Subject: Don't crash GenBCode for value classes with a self declaration If a value class has a self declaration class V(x: Long) extends AnyVal { self => /* ... */ } `vClassSymbol.typeOfThis.typeSymbol` is `class Long` in the backend. The InlineInfo for traits contains a field for the self type of the trait. This is required for re-writing calls to final trait methods to the static implementation method: the self type appears in the impl method signature. By mistake, the backend was recording the self type of all classes, not only of traits. In the case of a value class with a self declaration, this broke the assumption that the self type is always a class type (not a primitive type). The simple fix: only record the self type for traits. --- src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala index 162da4236a..eadc404bee 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala @@ -329,10 +329,12 @@ final class BCodeAsmCommon[G <: Global](val global: G) { * Build the [[InlineInfo]] for a class symbol. */ def buildInlineInfoFromClassSymbol(classSym: Symbol, classSymToInternalName: Symbol => InternalName, methodSymToDescriptor: Symbol => String): InlineInfo = { - val selfType = { + val traitSelfType = if (classSym.isTrait && !classSym.isImplClass) { // The mixin phase uses typeOfThis for the self parameter in implementation class methods. val selfSym = classSym.typeOfThis.typeSymbol if (selfSym != classSym) Some(classSymToInternalName(selfSym)) else None + } else { + None } val isEffectivelyFinal = classSym.isEffectivelyFinal @@ -394,6 +396,6 @@ final class BCodeAsmCommon[G <: Global](val global: G) { } }).toMap - InlineInfo(selfType, isEffectivelyFinal, methodInlineInfos, warning) + InlineInfo(traitSelfType, isEffectivelyFinal, methodInlineInfos, warning) } } -- cgit v1.2.3