This page is no longer maintained — Please continue to the home page at www.scala-lang.org

probable 2.9.0-1 compiler bug (fixed in 2.9.1-RC1) when defining Iterable.iterator with structural Iterator implementations

2 replies
Chris Twiner
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.

Hi All,

Sorry for the fluff title, can't think of a better one, I also can't
think of how better to search jira (summary ~ "\"Unknown type\""
brings nothing close, same for description except one for existentials
and one for dependent types) for this:

class BadIterable extends Iterable[Int] {

def iterator() =
if (System.getProperty("") == "fred")
new Iterator[Int]() {
def hasNext = false
def next() = 1
}
else
new Iterator[Int]() {
def hasNext = false
def next() = 2
}

}

will kill the 2.9.0-1 compiler:

java.lang.Error: Unknown type: Iterator[Int], [class
scala.tools.nsc.symtab.Types$TypeRef$$anon$6, class scala.t
ools.nsc.symtab.Types$ErrorType$] TypeRef? true
at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:35)
at scala.tools.nsc.backend.icode.TypeKinds$class.toTypeKind(TypeKinds.scala:390)
at scala.tools.nsc.backend.icode.ICodes.toTypeKind(ICodes.scala:25)
at scala.tools.nsc.backend.icode.TypeKinds$$anonfun$toTypeKind$1.apply(TypeKinds.scala:387)
at scala.tools.nsc.backend.icode.TypeKinds$$anonfun$toTypeKind$1.apply(TypeKinds.scala:387)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
.....

does this ring bells or should I raise a ticket and say its fixed in
RC1 in case anyone else hits this (or indeed add this example to the
text of an existing one)? Naming the Iterator types does work (ie.
making a class for them) as does a single direct structural type.

Cheers,
Chris

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: probable 2.9.0-1 compiler bug (fixed in 2.9.1-RC1) when def

I don't get this error, but I must be one or two weeks behind trunk.
Anyway, I'm guessing the problem comes from "iterator" being defined
as "iterator()" below, which is a different method. According to the
warning I get, the non-nullary method will override the nullary one.

On Wed, Aug 3, 2011 at 02:34, Chris Twiner wrote:
> Hi All,
>
> Sorry for the fluff title, can't think of a better one, I also can't
> think of how better to search jira (summary ~ "\"Unknown type\""
> brings nothing close, same for description except one for existentials
> and one for dependent types) for this:
>
> class BadIterable extends Iterable[Int] {
>
>  def iterator() =
>    if (System.getProperty("") == "fred")
>      new Iterator[Int]() {
>        def hasNext = false
>        def next() = 1
>      }
>    else
>      new Iterator[Int]() {
>        def hasNext = false
>        def next() = 2
>      }
>
> }
>
> will kill the 2.9.0-1 compiler:
>
> java.lang.Error: Unknown type: Iterator[Int], [class
> scala.tools.nsc.symtab.Types$TypeRef$$anon$6, class scala.t
> ools.nsc.symtab.Types$ErrorType$] TypeRef? true
>        at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:35)
>        at scala.tools.nsc.backend.icode.TypeKinds$class.toTypeKind(TypeKinds.scala:390)
>        at scala.tools.nsc.backend.icode.ICodes.toTypeKind(ICodes.scala:25)
>        at scala.tools.nsc.backend.icode.TypeKinds$$anonfun$toTypeKind$1.apply(TypeKinds.scala:387)
>        at scala.tools.nsc.backend.icode.TypeKinds$$anonfun$toTypeKind$1.apply(TypeKinds.scala:387)
>        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
> .....
>
> does this ring bells or should I raise a ticket and say its fixed in
> RC1 in case anyone else hits this (or indeed add this example to the
> text of an existing one)?  Naming the Iterator types does work (ie.
> making a class for them) as does a single direct structural type.
>
> Cheers,
> Chris
>

Chris Twiner
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: probable 2.9.0-1 compiler bug (fixed in 2.9.1-RC1) when def

Worth trying but doesn't change the outcome.

On Aug 3, 2011 10:27 PM, "Daniel Sobral" <dcsobral [at] gmail [dot] com> wrote:
>
> I don't get this error, but I must be one or two weeks behind trunk.
> Anyway, I'm guessing the problem comes from "iterator" being defined
> as "iterator()" below, which is a different method. According to the
> warning I get, the non-nullary method will override the nullary one.
>
> On Wed, Aug 3, 2011 at 02:34, Chris Twiner <chris [dot] twiner [at] gmail [dot] com> wrote:
> > Hi All,
> >
> > Sorry for the fluff title, can't think of a better one, I also can't
> > think of how better to search jira (summary ~ "\"Unknown type\""
> > brings nothing close, same for description except one for existentials
> > and one for dependent types) for this:
> >
> > class BadIterable extends Iterable[Int] {
> >
> >  def iterator() =
> >    if (System.getProperty("") == "fred")
> >      new Iterator[Int]() {
> >        def hasNext = false
> >        def next() = 1
> >      }
> >    else
> >      new Iterator[Int]() {
> >        def hasNext = false
> >        def next() = 2
> >      }
> >
> > }
> >
> > will kill the 2.9.0-1 compiler:
> >
> > java.lang.Error: Unknown type: Iterator[Int], <error> [class
> > scala.tools.nsc.symtab.Types$TypeRef$$anon$6, class scala.t
> > ools.nsc.symtab.Types$ErrorType$] TypeRef? true
> >        at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:35)
> >        at scala.tools.nsc.backend.icode.TypeKinds$class.toTypeKind(TypeKinds.scala:390)
> >        at scala.tools.nsc.backend.icode.ICodes.toTypeKind(ICodes.scala:25)
> >        at scala.tools.nsc.backend.icode.TypeKinds$$anonfun$toTypeKind$1.apply(TypeKinds.scala:387)
> >        at scala.tools.nsc.backend.icode.TypeKinds$$anonfun$toTypeKind$1.apply(TypeKinds.scala:387)
> >        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
> > .....
> >
> > does this ring bells or should I raise a ticket and say its fixed in
> > RC1 in case anyone else hits this (or indeed add this example to the
> > text of an existing one)?  Naming the Iterator types does work (ie.
> > making a class for them) as does a single direct structural type.
> >
> > Cheers,
> > Chris
> >
>
>
>
> --
> Daniel C. Sobral
>
> I travel to the future all the time.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland