From 86397c940a2b4df6166a9bc9ed3e03d008f4dd57 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 8 Jan 2009 16:23:11 +0000 Subject: fixed erroneous cyclic reference error conditio... fixed erroneous cyclic reference error condition; generated new starr. --- lib/scala-compiler.jar.desired.sha1 | 2 +- lib/scala-library-src.jar.desired.sha1 | 2 +- lib/scala-library.jar.desired.sha1 | 2 +- src/compiler/scala/tools/nsc/CompilationUnits.scala | 5 ++++- .../scala/tools/nsc/typechecker/Analyzer.scala | 7 ++++++- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 18 ++++++++++-------- .../scalax/collection/generic/VectorTemplate.scala | 2 +- .../collection/generic/covartest/VectorTemplate.scala | 2 +- .../scalax/collection/mutable/ArrayBuffer.scala | 3 ++- test/files/neg/structural.check | 6 +++--- test/files/pos/NoCyclicReference.scala | 7 +++++++ 11 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 test/files/pos/NoCyclicReference.scala diff --git a/lib/scala-compiler.jar.desired.sha1 b/lib/scala-compiler.jar.desired.sha1 index b3a59785b2..6bcc48448d 100644 --- a/lib/scala-compiler.jar.desired.sha1 +++ b/lib/scala-compiler.jar.desired.sha1 @@ -1 +1 @@ -7cd5469aa4e85530aa99234d983952589a030e8e ?scala-compiler.jar +9564f9861dd4c9711cd60bcc56d84c860aab486d ?scala-compiler.jar diff --git a/lib/scala-library-src.jar.desired.sha1 b/lib/scala-library-src.jar.desired.sha1 index 53f7fee70a..88e5328e7b 100644 --- a/lib/scala-library-src.jar.desired.sha1 +++ b/lib/scala-library-src.jar.desired.sha1 @@ -1 +1 @@ -6f717f2a07d59605f1937cae43bfb0c4e7376937 ?scala-library-src.jar +f434edbc25d88cc06cdf0f833116521018103627 ?scala-library-src.jar diff --git a/lib/scala-library.jar.desired.sha1 b/lib/scala-library.jar.desired.sha1 index 7adc0e712b..79f9a160f6 100644 --- a/lib/scala-library.jar.desired.sha1 +++ b/lib/scala-library.jar.desired.sha1 @@ -1 +1 @@ -4ad240bdf0649fb2b07b3d18a555134651329910 ?scala-library.jar +4def0800f45abbc5296dd599fe32ca102684de65 ?scala-library.jar diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala index bf02e114ab..aa7dc21909 100644 --- a/src/compiler/scala/tools/nsc/CompilationUnits.scala +++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala @@ -8,7 +8,7 @@ package scala.tools.nsc import scala.tools.nsc.util.{FreshNameCreator,OffsetPosition,Position,SourceFile} import scala.tools.nsc.io.AbstractFile -import scala.collection.mutable.{HashSet, HashMap} +import scala.collection.mutable.{HashSet, HashMap, ListBuffer} trait CompilationUnits { self: Global => @@ -34,6 +34,9 @@ trait CompilationUnits { self: Global => */ val synthetics = new HashMap[Symbol, Tree] + /** things to check at end of compilation unit */ + val toCheck = new ListBuffer[() => Unit] + /** used to track changes in a signature */ var pickleHash : Long = 0 diff --git a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala index ca9f654b76..7315c6f2c5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala @@ -38,7 +38,12 @@ trait Analyzer extends AnyRef def newPhase(_prev: Phase): StdPhase = new StdPhase(_prev) { if (!inIDE) resetTyper() def apply(unit: CompilationUnit) { - unit.body = newTyper(rootContext(unit)).typed(unit.body) + try { + unit.body = newTyper(rootContext(unit)).typed(unit.body) + for (workItem <- unit.toCheck) workItem() + } finally { + unit.toCheck.clear() + } } } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 34a7eb5732..8cc87d2321 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1556,17 +1556,19 @@ trait Typers { self: Analyzer => } } - def typedRefinement(stats: List[Tree]): List[Tree] = { + def typedRefinement(stats: List[Tree]) { namer.enterSyms(stats) - val stats1 = typedStats(stats, NoSymbol) - for (stat <- stats1 if stat.isDef) { - val member = stat.symbol - if (!(context.owner.info.baseClasses.tail forall - (bc => member.matchingSymbol(bc, context.owner.thisType) == NoSymbol))) { - member setFlag OVERRIDE + // need to delay rest of typedRefinement to avoid cyclic reference errors + unit.toCheck += { () => + val stats1 = typedStats(stats, NoSymbol) + for (stat <- stats1 if stat.isDef) { + val member = stat.symbol + if (!(context.owner.info.baseClasses.tail forall + (bc => member.matchingSymbol(bc, context.owner.thisType) == NoSymbol))) { + member setFlag OVERRIDE + } } } - stats1 } def typedImport(imp : Import) : Import = imp diff --git a/src/library/scalax/collection/generic/VectorTemplate.scala b/src/library/scalax/collection/generic/VectorTemplate.scala index bc18ac45c2..cd3412498d 100644 --- a/src/library/scalax/collection/generic/VectorTemplate.scala +++ b/src/library/scalax/collection/generic/VectorTemplate.scala @@ -34,7 +34,7 @@ self => x } else Iterator.empty.next def head = - self(i) + if (i < end) self(i) else Iterator.empty.next /** drop is overridden to enable fast searching in the middle of random access sequences */ override def drop(n: Int): Iterator[A] = if (n > 0) new Elements(start + n, end) else this diff --git a/src/library/scalax/collection/generic/covartest/VectorTemplate.scala b/src/library/scalax/collection/generic/covartest/VectorTemplate.scala index 6e44b6a6c5..474fb9ad7e 100644 --- a/src/library/scalax/collection/generic/covartest/VectorTemplate.scala +++ b/src/library/scalax/collection/generic/covartest/VectorTemplate.scala @@ -34,7 +34,7 @@ self => x } else Iterator.empty.next def head = - self(i) + if (i < end) self(i) else Iterator.empty.next /** drop is overridden to enable fast searching in the middle of random access sequences */ override def drop(n: Int): Iterator[A] = if (n > 0) new Elements(start + n, end) else this diff --git a/src/library/scalax/collection/mutable/ArrayBuffer.scala b/src/library/scalax/collection/mutable/ArrayBuffer.scala index 3e4877cef7..634e002111 100644 --- a/src/library/scalax/collection/mutable/ArrayBuffer.scala +++ b/src/library/scalax/collection/mutable/ArrayBuffer.scala @@ -93,7 +93,8 @@ class ArrayBuffer[A] extends Buffer[A] with Builder[ArrayBuffer, A] with Resizab /** Removes the element on a given index position. It takes time linear in * the buffer size. * - * @param n the index which refers to the element to delete. + * @param n the index which refers to the first element to delete. + * @param count the number of elemenets to delete * @return the updated array buffer. * @throws Predef.IndexOutOfBoundsException if n is out of bounds. */ diff --git a/test/files/neg/structural.check b/test/files/neg/structural.check index a0342c4d9c..3a4a627b26 100644 --- a/test/files/neg/structural.check +++ b/test/files/neg/structural.check @@ -1,6 +1,9 @@ structural.scala:3: error: illegal dependent method type def f(x: { type D; def m: D }) = x.m ^ +structural.scala:19: error: illegal dependent method type + def f9[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: AnyRef): D }) = x.m[Tata](()) //suceed + ^ structural.scala:10: error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement def f1[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: A): AnyRef; val x: A }) = x.m[Tata](x.x) //fail ^ @@ -10,9 +13,6 @@ structural.scala:11: error: Parameter type in structural refinement may not refe structural.scala:12: error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement def f3[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: C): AnyRef; val x: C }) = x.m[Tata](x.x) //fail ^ -structural.scala:19: error: illegal dependent method type - def f9[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: AnyRef): D }) = x.m[Tata](()) //suceed - ^ structural.scala:42: error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement type Summable[T] = { def +(v : T) : T } ^ diff --git a/test/files/pos/NoCyclicReference.scala b/test/files/pos/NoCyclicReference.scala new file mode 100644 index 0000000000..e42896661e --- /dev/null +++ b/test/files/pos/NoCyclicReference.scala @@ -0,0 +1,7 @@ +package test + +trait Iterable[+A] { self => + + type CC[B] <: Iterable[B] { type CC[C] = self.CC[C] } + +} -- cgit v1.2.3