Bug 18215 - GCJ disallows some references to 'this' from an enclosing class
Summary: GCJ disallows some references to 'this' from an enclosing class
Status: RESOLVED DUPLICATE of bug 4695
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-29 03:51 UTC by Casey Marshall
Modified: 2005-07-23 22:49 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Casey Marshall 2004-10-29 03:51:37 UTC
In the constructor of a member class, GCJ does not allow you to do a 'super'
call with an argument that calls an instance method of the enclosing class.

For example, GCJ rejects this perfectly valid class:

--- outer.java ---
public class outer
{
  private String name;

  public outer (String name)
  {
    this.name = name;
  }

  public String getID()
  {
    return name;
  }

  public class inner extends Thread
  {
    public inner()
    {
      super ("thread-" + getID());
    }
  }
}
--- outer.java ---

This is valid because the call to 'getID()' is referencing the 'this' from the
enclosing class. GCJ also rejects 'outer.this.getID()' in this example, so there
does not appear to be a workaround.

GCJ fails with:
outer.java: In class `outer$inner':
outer.java: In constructor `(outer)':
outer.java:19: error: Can't reference `this' before the superclass constructor
has been called.
         super ("thread-" + outer.this.getID());
                                       ^
1 error

Tested on:
gcj (GCC) 3.4.2
gcj (GCC) 4.0.0 20041025 (experimental)
Comment 1 Andrew Pinski 2004-10-29 03:54:04 UTC

*** This bug has been marked as a duplicate of 4695 ***