From c8831a9eb03797449cd4371539fc4afb2ff38814 Mon Sep 17 00:00:00 2001 From: dragos Date: Mon, 30 Nov 2009 16:42:35 +0000 Subject: [PATCH] Closed #2726 and added test for #2464 (refs #2464) git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@19945 5e8d7ff9-d8ef-0310-90f0-a4852d11357a --- scala-lang.ipr | 2 +- .../symtab/classfile/ClassfileParser.scala | 31 +++++++++++++------ test/files/pos/t2464/JavaOne.java | 5 +++ test/files/pos/t2464/ScalaOne_1.scala | 6 ++++ test/files/pos/t2464/t2464_2.scala | 3 ++ test/files/pos/t2726/SQLBuilder_1.scala | 7 +++++ test/files/pos/t2726/test_2.scala | 3 ++ 7 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 test/files/pos/t2464/JavaOne.java create mode 100644 test/files/pos/t2464/ScalaOne_1.scala create mode 100644 test/files/pos/t2464/t2464_2.scala create mode 100644 test/files/pos/t2726/SQLBuilder_1.scala create mode 100644 test/files/pos/t2726/test_2.scala diff --git a/scala-lang.ipr b/scala-lang.ipr index dced049dc..750442f47 100644 --- a/scala-lang.ipr +++ b/scala-lang.ipr @@ -72,7 +72,7 @@ - + diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 7561e2d13..273235650 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -408,6 +408,25 @@ abstract class ClassfileParser { var nameIdx = in.nextChar externalName = pool.getClassName(nameIdx) val c = if (externalName.toString.indexOf('$') < 0) pool.getClassSymbol(nameIdx) else clazz + + /** Parse parents for Java classes. For Scala, return AnyRef, since the real type will be unpickled. + * Updates the read pointer of 'in'. */ + def parseParents: List[Type] = { + if (isScala) { + in.nextChar // skip superclass + val ifaces = in.nextChar + in.bp += ifaces * 2 // .. and iface count interfaces + List(definitions.AnyRefClass.tpe) // dummy superclass, will be replaced by pickled information + } else { + val superType = if (isAnnotation) { in.nextChar; definitions.AnnotationClass.tpe } + else pool.getSuperClass(in.nextChar).tpe + val ifaceCount = in.nextChar + var ifaces = for (i <- List.range(0, ifaceCount)) yield pool.getSuperClass(in.nextChar).tpe + if (isAnnotation) ifaces = definitions.ClassfileAnnotationClass.tpe :: ifaces + superType :: ifaces + } + } + if (c != clazz && externalName.toString.indexOf("$") < 0) { if ((clazz eq NoSymbol) && (c ne NoSymbol)) clazz = c else throw new IOException("class file '" + in.file + "' contains wrong " + c) @@ -415,16 +434,10 @@ abstract class ClassfileParser { addEnclosingTParams(clazz) parseInnerClasses() // also sets the isScala / isScalaRaw / hasMeta flags, see r15956 - val superType = if (isAnnotation) { in.nextChar; definitions.AnnotationClass.tpe } - else pool.getSuperClass(in.nextChar).tpe - val ifaceCount = in.nextChar - var ifaces = for (i <- List.range(0, ifaceCount)) yield pool.getSuperClass(in.nextChar).tpe - if (isAnnotation) ifaces = definitions.ClassfileAnnotationClass.tpe :: ifaces - val parents = superType :: ifaces - // get the class file parser to reuse scopes. + // get the class file parser to reuse scopes. instanceDefs = new Scope staticDefs = new Scope - val classInfo = ClassInfoType(parents, instanceDefs, clazz) + val classInfo = ClassInfoType(parseParents, instanceDefs, clazz) val staticInfo = ClassInfoType(List(), staticDefs, statics) if (!isScala && !isScalaRaw) { @@ -945,7 +958,7 @@ abstract class ClassfileParser { in.skip(attrLen) case nme.ScalaATTR => isScalaRaw = true - case nme.InnerClassesATTR => + case nme.InnerClassesATTR if !isScala => val entries = in.nextChar.toInt for (i <- 0 until entries) { val innerIndex = in.nextChar.toInt diff --git a/test/files/pos/t2464/JavaOne.java b/test/files/pos/t2464/JavaOne.java new file mode 100644 index 000000000..ff36868a0 --- /dev/null +++ b/test/files/pos/t2464/JavaOne.java @@ -0,0 +1,5 @@ +class ClassTwo { + public static class Child { + public void func2() {return ;} + } +} diff --git a/test/files/pos/t2464/ScalaOne_1.scala b/test/files/pos/t2464/ScalaOne_1.scala new file mode 100644 index 000000000..0271b9ce7 --- /dev/null +++ b/test/files/pos/t2464/ScalaOne_1.scala @@ -0,0 +1,6 @@ +class ScalaClassOne extends ClassTwo.Child { + def func4() = { + func2 + } +} + diff --git a/test/files/pos/t2464/t2464_2.scala b/test/files/pos/t2464/t2464_2.scala new file mode 100644 index 000000000..13a52c952 --- /dev/null +++ b/test/files/pos/t2464/t2464_2.scala @@ -0,0 +1,3 @@ +object Test { + val c1 = new ScalaClassOne +} diff --git a/test/files/pos/t2726/SQLBuilder_1.scala b/test/files/pos/t2726/SQLBuilder_1.scala new file mode 100644 index 000000000..7b3e3d832 --- /dev/null +++ b/test/files/pos/t2726/SQLBuilder_1.scala @@ -0,0 +1,7 @@ +class SQLBuilder extends SQLBuilder.Segment + +object SQLBuilder { + trait Segment +} + + diff --git a/test/files/pos/t2726/test_2.scala b/test/files/pos/t2726/test_2.scala new file mode 100644 index 000000000..e738143ae --- /dev/null +++ b/test/files/pos/t2726/test_2.scala @@ -0,0 +1,3 @@ +object SQuery2Test { + new SQLBuilder +}