public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug java/18147] New: Objects in instance initializer blocks are scoped too widely
@ 2004-10-25 18:46 csm at gnu dot org
  2004-10-25 18:49 ` [Bug java/18147] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: csm at gnu dot org @ 2004-10-25 18:46 UTC (permalink / raw)
  To: java-prs

If you declare an object within an instance initializer, you cannot declare
another object of the same name in a different instance initializer.

This description seems pretty opaque, so an example of correct code that GCJ
rejects is probably better:

-- init.java --
import java.util.HashMap;
class init
{
  private final HashMap _map1 = new HashMap();
  {
    Object foo = new Object();
    _map1.put ("foo!", foo);
  }

  private final HashMap _map2 = new HashMap();
  {
    Object foo = new Object();
    _map2.put ("bar!", foo);
  }
}
-- init.java --

GCJ exits with this error:

init.java:13: error: Variable `foo' is already defined in this method and was
declared `Object foo' at line 7.
       Object foo = new Object();
              ^
1 error

-- 
           Summary: Objects in instance initializer blocks are scoped too
                    widely
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: csm at gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18147


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug java/18147] Objects in instance initializer blocks are scoped too widely
  2004-10-25 18:46 [Bug java/18147] New: Objects in instance initializer blocks are scoped too widely csm at gnu dot org
@ 2004-10-25 18:49 ` pinskia at gcc dot gnu dot org
  2004-10-25 18:55 ` tromey at gcc dot gnu dot org
  2005-01-24  0:57 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-25 18:49 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-25 18:49 -------
Confirmed, a workaround is to do something like this:
import java.util.HashMap;
class init
{
  {{
    Object foo = new Object();}
  }
  {
    Object foo = new Object();
  }
}

The reduced testcase:
import java.util.HashMap;
class init
{
  {
    Object foo = new Object();
  }
  {
    Object foo = new Object();
  }
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |rejects-valid
   Last reconfirmed|0000-00-00 00:00:00         |2004-10-25 18:49:33
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18147


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug java/18147] Objects in instance initializer blocks are scoped too widely
  2004-10-25 18:46 [Bug java/18147] New: Objects in instance initializer blocks are scoped too widely csm at gnu dot org
  2004-10-25 18:49 ` [Bug java/18147] " pinskia at gcc dot gnu dot org
@ 2004-10-25 18:55 ` tromey at gcc dot gnu dot org
  2005-01-24  0:57 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: tromey at gcc dot gnu dot org @ 2004-10-25 18:55 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From tromey at gcc dot gnu dot org  2004-10-25 18:55 -------
As a workaround you can put an extra block inside the
instance initializers:

{{ Object foo = ... }}

The bug here seems to be that gcj chains the statements
of each initializer block together when making finit.
Instead, however, it should treat each as a separate
block and chain the blocks together.  That is, an
instance initializer block introduces a new scope.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18147


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug java/18147] Objects in instance initializer blocks are scoped too widely
  2004-10-25 18:46 [Bug java/18147] New: Objects in instance initializer blocks are scoped too widely csm at gnu dot org
  2004-10-25 18:49 ` [Bug java/18147] " pinskia at gcc dot gnu dot org
  2004-10-25 18:55 ` tromey at gcc dot gnu dot org
@ 2005-01-24  0:57 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-24  0:57 UTC (permalink / raw)
  To: java-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
   Last reconfirmed|2004-10-25 18:49:33         |2005-01-24 00:57:56
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18147


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-01-24  0:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-25 18:46 [Bug java/18147] New: Objects in instance initializer blocks are scoped too widely csm at gnu dot org
2004-10-25 18:49 ` [Bug java/18147] " pinskia at gcc dot gnu dot org
2004-10-25 18:55 ` tromey at gcc dot gnu dot org
2005-01-24  0:57 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).