From f2a9a7a9b6d3ae9699f5f50b8683db05d9a1f6e0 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Wed, 4 Feb 2015 16:14:23 +0100 Subject: Fix #349 module class after erasure could have selfType be a MethodType ExprType erases to MethodType and need to be handled. --- src/dotty/tools/dotc/core/SymDenotations.scala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 6b3532944..8e591f677 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -622,15 +622,22 @@ object SymDenotations { * the completers. */ /** The class implementing this module, NoSymbol if not applicable. */ - final def moduleClass(implicit ctx: Context): Symbol = + final def moduleClass(implicit ctx: Context): Symbol = { + def notFound = {println(s"missing module class for $name: $myInfo"); NoSymbol} if (this is ModuleVal) myInfo match { case info: TypeRef => info.symbol case ExprType(info: TypeRef) => info.symbol // needed after uncurry, when module terms might be accessor defs case info: LazyType => info.moduleClass - case _ => println(s"missing module class for $name: $myInfo"); NoSymbol + case t: MethodType => + t.resultType match { + case info: TypeRef => info.symbol + case _ => notFound + } + case _ => notFound } else NoSymbol + } /** The module implemented by this module class, NoSymbol if not applicable. */ final def sourceModule(implicit ctx: Context): Symbol = myInfo match { -- cgit v1.2.3 From 89e897072e75ea0644f6d728cf062f4fa7981443 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Mon, 9 Feb 2015 14:47:50 +0100 Subject: Fix #348 flatten short name shouldn't include package names --- src/dotty/tools/dotc/core/SymDenotations.scala | 15 +++++++++++++++ src/dotty/tools/dotc/transform/Flatten.scala | 2 +- src/dotty/tools/dotc/transform/SymUtils.scala | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 8e591f677..bce4322ff 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -292,6 +292,21 @@ object SymDenotations { if (isType) fn.toTypeName else fn.toTermName } + + /** The encoded flat name of this denotation, where joined names are separated by `separator` characters. */ + def flatName(separator: Char = '$')(implicit ctx: Context): Name = + if (symbol == NoSymbol || owner == NoSymbol || owner.isEffectiveRoot || (owner is PackageClass)) name + else { + var owner = this + var sep = "" + do { + owner = owner.owner + sep += separator + } while (!owner.isClass && !owner.isPackageObject) + val fn = owner.flatName(separator) ++ sep ++ name + if (isType) fn.toTypeName else fn.toTermName + } + /** `fullName` where `.' is the separator character */ def fullName(implicit ctx: Context): Name = fullNameSeparated('.') diff --git a/src/dotty/tools/dotc/transform/Flatten.scala b/src/dotty/tools/dotc/transform/Flatten.scala index ff3f06c68..0bd1bb75f 100644 --- a/src/dotty/tools/dotc/transform/Flatten.scala +++ b/src/dotty/tools/dotc/transform/Flatten.scala @@ -19,7 +19,7 @@ class Flatten extends MiniPhaseTransform with SymTransformer { thisTransform => def transformSym(ref: SymDenotation)(implicit ctx: Context) = { if (ref.isClass && !ref.is(Package) && !ref.owner.is(Package)) { ref.copySymDenotation( - name = ref.flatName, + name = ref.flatName(), owner = ref.enclosingPackageClass) } else ref diff --git a/src/dotty/tools/dotc/transform/SymUtils.scala b/src/dotty/tools/dotc/transform/SymUtils.scala index 0a5854ea7..c38b7cebd 100644 --- a/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/src/dotty/tools/dotc/transform/SymUtils.scala @@ -93,7 +93,7 @@ class SymUtils(val self: Symbol) extends AnyVal { self.owner.info.decl(self.asTerm.name.fieldName).suchThat(!_.is(Method)).symbol /** `fullName` where `$' is the separator character */ - def flatName(implicit ctx: Context): Name = self.fullNameSeparated('$') + def flatName(implicit ctx: Context): Name = self.flatName('$') def initializer(implicit ctx: Context): TermSymbol = self.owner.info.decl(InitializerName(self.asTerm.name)).symbol.asTerm -- cgit v1.2.3 From fb84ab55f4fd234c35ad85083092e9c5fe676370 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Tue, 10 Feb 2015 13:19:27 +0100 Subject: Disable t2667 that fails inside Extension methods. This info transformation was left untriggered before backend was enabled. --- src/dotty/tools/dotc/transform/ExtensionMethods.scala | 2 +- tests/disabled/t2667.scala | 7 +++++++ tests/pos/t2667.scala | 6 ------ 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 tests/disabled/t2667.scala delete mode 100644 tests/pos/t2667.scala diff --git a/src/dotty/tools/dotc/transform/ExtensionMethods.scala b/src/dotty/tools/dotc/transform/ExtensionMethods.scala index 2ff43c55b..a006f04a7 100644 --- a/src/dotty/tools/dotc/transform/ExtensionMethods.scala +++ b/src/dotty/tools/dotc/transform/ExtensionMethods.scala @@ -35,7 +35,7 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful case ref: ClassDenotation if ref is ModuleClass => ref.linkedClass match { case origClass: ClassSymbol if isDerivedValueClass(origClass) => - val cinfo = ref.classInfo + val cinfo = ref.classInfo // ./tests/pos/t2667.scala dies here for module class AnyVal$ val decls1 = cinfo.decls.cloneScope ctx.atPhase(thisTransformer.next) { implicit ctx => for (decl <- origClass.classInfo.decls) { diff --git a/tests/disabled/t2667.scala b/tests/disabled/t2667.scala new file mode 100644 index 000000000..600c1eaf0 --- /dev/null +++ b/tests/disabled/t2667.scala @@ -0,0 +1,7 @@ +// ExtensionMethods info transformer fails here for AnyVal$ +object A { + def foo(x: Int, y: Int*): Int = 45 + def foo[T](x: T*): Int = 55 + + val x: Unit = foo(23, 23f) +} diff --git a/tests/pos/t2667.scala b/tests/pos/t2667.scala deleted file mode 100644 index 7f1f36f00..000000000 --- a/tests/pos/t2667.scala +++ /dev/null @@ -1,6 +0,0 @@ -object A { - def foo(x: Int, y: Int*): Int = 45 - def foo[T](x: T*): Int = 55 - - val x: Unit = foo(23, 23f) -} -- cgit v1.2.3 From 1892e77808b148eba34c409db98d15a886a74069 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Tue, 10 Feb 2015 13:21:17 +0100 Subject: Disable t2669 dies in Classfile parser while parsing java.util.Vector(requested by backend) --- tests/disabled/t2669.scala | 29 +++++++++++++++++++++++++++++ tests/pos/t2669.scala | 28 ---------------------------- 2 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 tests/disabled/t2669.scala delete mode 100644 tests/pos/t2669.scala diff --git a/tests/disabled/t2669.scala b/tests/disabled/t2669.scala new file mode 100644 index 000000000..609e88786 --- /dev/null +++ b/tests/disabled/t2669.scala @@ -0,0 +1,29 @@ +// #2629, #2639, #2669 +// dies in classfile parser while parsing java.util.Vector(requested by bakend) +object Test2669 { + + def test[T](l: java.util.ArrayList[_ <: T]) = 1 + test(new java.util.ArrayList[String]()) + +} + +import java.util.ArrayList + +object Test2629 { + def main(args: Array[String]): Unit = { + val l = new ArrayList[String](1) + val m = new ArrayList(l) + + println(l.size) + println(m.size) + } +} + + +import java.util.Vector + +// scalac cannot detect lack of type params, but then throws AssertionError later: +class TVector2639 { + val b = new Vector // this line passed without error detected + val a = new Vector(1) // this line caused throwing AssertionError when scalac +} diff --git a/tests/pos/t2669.scala b/tests/pos/t2669.scala deleted file mode 100644 index 72e931178..000000000 --- a/tests/pos/t2669.scala +++ /dev/null @@ -1,28 +0,0 @@ -// #2629, #2639, #2669 -object Test2669 { - - def test[T](l: java.util.ArrayList[_ <: T]) = 1 - test(new java.util.ArrayList[String]()) - -} - -import java.util.ArrayList - -object Test2629 { - def main(args: Array[String]): Unit = { - val l = new ArrayList[String](1) - val m = new ArrayList(l) - - println(l.size) - println(m.size) - } -} - - -import java.util.Vector - -// scalac cannot detect lack of type params, but then throws AssertionError later: -class TVector2639 { - val b = new Vector // this line passed without error detected - val a = new Vector(1) // this line caused throwing AssertionError when scalac -} -- cgit v1.2.3 From 5027f018be2879d0db5a13037abe4ac706ffbf42 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Tue, 10 Feb 2015 13:52:19 +0100 Subject: Assert for overflows in Periods --- src/dotty/tools/dotc/core/Periods.scala | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/dotty/tools/dotc/core/Periods.scala b/src/dotty/tools/dotc/core/Periods.scala index 66c26e381..cef85a07f 100644 --- a/src/dotty/tools/dotc/core/Periods.scala +++ b/src/dotty/tools/dotc/core/Periods.scala @@ -119,16 +119,26 @@ object Periods { object Period { /** The single-phase period consisting of given run id and phase id */ - def apply(rid: RunId, pid: PhaseId): Period = + def apply(rid: RunId, pid: PhaseId): Period = { + assert(rid <= MaxPossibleRunId) + assert(pid <= MaxPossiblePhaseId) new Period(((rid << PhaseWidth) | pid) << PhaseWidth) + } /** The period consisting of given run id, and lo/hi phase ids */ - def apply(rid: RunId, loPid: PhaseId, hiPid: PhaseId): Period = + def apply(rid: RunId, loPid: PhaseId, hiPid: PhaseId): Period = { + assert(rid <= MaxPossibleRunId) + assert(loPid <= MaxPossiblePhaseId) + assert(hiPid <= MaxPossiblePhaseId) + new Period(((rid << PhaseWidth) | hiPid) << PhaseWidth | (hiPid - loPid)) + } /** The interval consisting of all periods of given run id */ - def allInRun(rid: RunId) = + def allInRun(rid: RunId) = { + assert(rid <= MaxPossibleRunId) apply(rid, 0, PhaseMask) + } } final val Nowhere = new Period(0) @@ -141,6 +151,8 @@ object Periods { type RunId = Int final val NoRunId = 0 final val InitialRunId = 1 + final val RunWidth = java.lang.Integer.SIZE - PhaseWidth * 2 - 1/* sign */ + final val MaxPossibleRunId = (1 << RunWidth) - 1 /** An ordinal number for phases. First phase has number 1. */ type PhaseId = Int -- cgit v1.2.3 From 10167c46191c1b02246635b01dcd3d1e0b75497a Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Thu, 12 Feb 2015 16:22:36 +0100 Subject: Check period validity once per run. --- src/dotty/tools/dotc/Run.scala | 3 +++ src/dotty/tools/dotc/core/Periods.scala | 7 ------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala index abee30aab..a182029e6 100644 --- a/src/dotty/tools/dotc/Run.scala +++ b/src/dotty/tools/dotc/Run.scala @@ -13,6 +13,9 @@ import scala.reflect.io.VirtualFile class Run(comp: Compiler)(implicit ctx: Context) { + assert(comp.phases.last.last.id <= Periods.MaxPossiblePhaseId) + assert(ctx.runId <= Periods.MaxPossibleRunId) + var units: List[CompilationUnit] = _ def getSource(fileName: String): SourceFile = { diff --git a/src/dotty/tools/dotc/core/Periods.scala b/src/dotty/tools/dotc/core/Periods.scala index cef85a07f..b4e22bd87 100644 --- a/src/dotty/tools/dotc/core/Periods.scala +++ b/src/dotty/tools/dotc/core/Periods.scala @@ -120,23 +120,16 @@ object Periods { /** The single-phase period consisting of given run id and phase id */ def apply(rid: RunId, pid: PhaseId): Period = { - assert(rid <= MaxPossibleRunId) - assert(pid <= MaxPossiblePhaseId) new Period(((rid << PhaseWidth) | pid) << PhaseWidth) } /** The period consisting of given run id, and lo/hi phase ids */ def apply(rid: RunId, loPid: PhaseId, hiPid: PhaseId): Period = { - assert(rid <= MaxPossibleRunId) - assert(loPid <= MaxPossiblePhaseId) - assert(hiPid <= MaxPossiblePhaseId) - new Period(((rid << PhaseWidth) | hiPid) << PhaseWidth | (hiPid - loPid)) } /** The interval consisting of all periods of given run id */ def allInRun(rid: RunId) = { - assert(rid <= MaxPossibleRunId) apply(rid, 0, PhaseMask) } } -- cgit v1.2.3