Date: Mon, 12 May 2003 14:42:36 -0400 (EDT)
From: C. Scott Ananian
To: jsr14-prototype-comments@sun.com
Subject: "cyclic inheritance" problem.

The following program fails to compile (1.0-1.3 prototypes) with an error
about "cyclic inheritance involving F":
---
class G<N extends Node<N>> {
    static class Node<N extends Node<N>> {
    }
}
class F extends G<MyNode> {
    static class MyNode extends G.Node<MyNode> {
    }
}
---
Making F.MyNode a separate class MyNode instead of an inner class fixes
the problem; see the attached sunbug.tgz for full details.  I can't read
the JLS definition of cyclic inheritance (JLS 8.1.3/9.1.2/14.3, although
8.1.3 is the only applicable section) as prohibiting this code in any
way, but then again 8.1.3 doesn't really state whether F.MyNode is meant
to "depend on" F or not.  The same program stripped of type parameters
(again, see sunbug.tgz) compiles without errors, which leads me to think
this is an error in how type parameters play into the cyclic inheritance
definition.

This is a relevant problem because it will arise in any definition of a
Graph interface using an inner class Graph.Node to represent nodes.  An
actual implementation of the interface will want to have code like the
above, leading to a confusing-at-best likely-erroneous situation.
  --scott

    [ Part 2, ""  Application/OCTET-STREAM (Name: "sunbug.tgz")  1.1KB. ]

Date: Mon, 12 May 2003 14:37:27 -0700
From: Neal M Gafter
To: C. Scott Ananian
Cc: jsr14-prototype-comments@sun.com
Subject: Re: "cyclic inheritance" problem.

[...]
This is now bugid 4862621.  It should show up on jdc in a couple of days.

The name "MyNode" appearing in the extends clause of F isn't
correct, because MyNode isn't in scope there.  That is another
compiler bug.

-Neal

Date: Mon, 12 May 2003 18:06:41 -0400 (EDT)
From: C. Scott Ananian
To: Neal M Gafter
Cc: jsr14-prototype-comments@sun.com
Subject: Re: "cyclic inheritance" problem.

[...]
would this be legal then?

class G<N extends Node<N>> {
     static class Node<N extends Node<N>> { }
}
class F extends G<F.MyNode> { // <- note I'm naming F explicitly.
     static class MyNode extends G.Node<MyNode> { }
}

...or would I have to resort to this:

class G<N extends Node<N>> {
     static class Node<N extends Node<N>> { }
}
class F<N extends MyNode> extends G<N> {
     static class MyNode extends G.Node<MyNode> { }
}
[...]
 --scott

explosives South Africa blowfish Legion of Doom Rule Psix Chechnya 
SSBN 743 Iraq class struggle RNC hack Diplomat chemical agent insurgent 
                         ( http://cscott.net/ )

Date: Mon, 12 May 2003 16:49:56 -0700
From: Neal Gafter
To: C. Scott Ananian
Cc: jsr14-prototype-comments@sun.com
Subject: Re: "cyclic inheritance" problem.

C. Scott Ananian wrote:
[...]
> would this be legal then?
> 
> class G<N extends Node<N>> {
>      static class Node<N extends Node<N>> { }
> }
> class F extends G<F.MyNode> { // <- note I'm naming F explicitly.
>      static class MyNode extends G.Node<MyNode> { }
> }

Yes, once I have the bugs fixed.

Valid XHTML 1.0!