Bug 7298 - Can't call method of outer class from inner constructor
Summary: Can't call method of outer class from inner constructor
Status: RESOLVED DUPLICATE of bug 4695
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2002-07-12 18:46 UTC by jmr
Modified: 2003-08-10 03:54 UTC (History)
3 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: 2003-08-09 16:18:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jmr 2002-07-12 18:46:00 UTC
	A method of an outer class cannot be called from the inner class
        constructor before the constructor for the inner class's superclass
        has been called.  The outer class has been constructed, so this
        should be allowed.

Release:
3.2 20020710 (experimental)

Environment:
System: Linux churchill 2.4.3-12 #1 Fri Jun 8 15:05:56 EDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure --prefix=/home/user/jmr/app/gcc

How-To-Repeat:

	X.java:

        public class X {
            Object f() {
                return null;
            }
            class XX {
                XX() {
                    this(f());
                }

                XX(Object o) {
                }
            }
        }

        gcj -v X.java yields:

        Reading specs from /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
        Reading specs from /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.2/../../../libgcj.spec
        rename spec lib to liborig
        Configured with: ./configure --prefix=/home/user/jmr/app/gcc
        Thread model: single
        gcc version 3.2 20020710 (experimental)
         /home/user/jmr/app/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.2/jc1 X.java -fno-use-divide-subroutine -fuse-boehm-gc -fnon-call-exceptions -fkeep-inline-functions -quiet -dumpbase X.java -g1 -version -o /tmp/ccZQXE2X.s
        GNU Java version 3.2 20020710 (experimental) (i686-pc-linux-gnu)
                compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-85).
        Class path starts here:
            /home/user/jmr/gcj_test/inner2/
            /home/user/jmr/app/gcc/share/java/libgcj-3.2.jar/ (system) (zip)
        X.java: In class `X$XX':
        X.java: In constructor `(X)':
        X.java:7: error: Can't reference `this' before the superclass constructor has been called.
                       this(f());
                            ^
        1 error

        This works with javac.
Comment 1 jmr 2002-07-12 18:46:00 UTC
Fix:
	This could be worked around by passing a reference to the outer
        class into the constructor.

        public class X {
            Object f() {
                return null;
            }
            class XX {
                XX(X x) {
                    this(x.f());
                }

                XX(Object o) {
                }
            }
        }
Comment 2 Dara Hazeghi 2003-05-12 13:20:17 UTC
From: Dara Hazeghi <dhazeghi@yahoo.com>
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: java/7298: Can't call method of outer class from inner constructor
Date: Mon, 12 May 2003 13:20:17 -0700

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit- 
 trail&database=gcc&pr=7298
 
 Hello,
 
 I can confirm that this bug still occurs on gcc 3.2, 3.3 branch and  
 mainline (20030511) on i686-linux.
 
 Dara
Comment 3 Andrew Pinski 2003-05-26 14:19:51 UTC
Confirmed by Dara.
Comment 4 Andrew Pinski 2003-08-10 03:54:19 UTC
This is a dup of bug 4695.

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