public inbox for java-prs@sourceware.org help / color / mirror / Atom feed
* [Bug java/32638] New: Wrong selection of field in inner class when outer class and super class have a relevant filed named the same @ 2007-07-05 17:12 mark at gcc dot gnu dot org 2007-07-05 17:31 ` [Bug java/32638] " tromey at gcc dot gnu dot org 2007-07-05 18:34 ` mark at klomp dot org 0 siblings, 2 replies; 3+ messages in thread From: mark at gcc dot gnu dot org @ 2007-07-05 17:12 UTC (permalink / raw) To: java-prs The following program should print true, but prints false when compiled with gcj -C because the wrong field o is selected in the anonymous inner class (the protected field named o in the super class is more specific than the field o in the enclosing method). public class t { static abstract class a { protected Object o = new Object(); abstract void print(Object input); } static class b { void m() { final Object o = new Object(); a x = new a() { void print(Object input) { System.out.println(o != input); } }; x.print(o); } } public static void main(String[] args) { new b().m(); } } Since this is pretty hard to see why this code works/doesn't work in the first place (the super class could be in a completely different file and the field in the outer class certainly looks like it would be the one that is used in the inner class) a warning for this kind of usage would be nice. gcj (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13) -- Summary: Wrong selection of field in inner class when outer class and super class have a relevant filed named the same Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: java AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mark at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32638 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug java/32638] Wrong selection of field in inner class when outer class and super class have a relevant filed named the same 2007-07-05 17:12 [Bug java/32638] New: Wrong selection of field in inner class when outer class and super class have a relevant filed named the same mark at gcc dot gnu dot org @ 2007-07-05 17:31 ` tromey at gcc dot gnu dot org 2007-07-05 18:34 ` mark at klomp dot org 1 sibling, 0 replies; 3+ messages in thread From: tromey at gcc dot gnu dot org @ 2007-07-05 17:31 UTC (permalink / raw) To: java-prs ------- Comment #1 from tromey at gcc dot gnu dot org 2007-07-05 17:31 ------- I tried this with svn trunk and got 'false'. If there is a bug here it is in ecj, not gcj. I'm not sure I agree with your interpretation here. I don't see how specificity applies. Isn't that term only used for overload resolution? It's been a while since I was completely familiar with the JLS, though ... where are you reading? IMO the JLS could be clearer here, but I believe the local 'o' shadows the field a.o. See: http://java.sun.com/docs/books/jls/third_edition/html/names.html#34133 Anyway, I suggest filing against ecj or perhaps the JDK for resolution. -- tromey at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tromey at gcc dot gnu dot | |org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32638 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug java/32638] Wrong selection of field in inner class when outer class and super class have a relevant filed named the same 2007-07-05 17:12 [Bug java/32638] New: Wrong selection of field in inner class when outer class and super class have a relevant filed named the same mark at gcc dot gnu dot org 2007-07-05 17:31 ` [Bug java/32638] " tromey at gcc dot gnu dot org @ 2007-07-05 18:34 ` mark at klomp dot org 1 sibling, 0 replies; 3+ messages in thread From: mark at klomp dot org @ 2007-07-05 18:34 UTC (permalink / raw) To: java-prs [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 2799 bytes --] ------- Comment #2 from mark at gcc dot gnu dot org 2007-07-05 18:34 ------- Subject: Re: Wrong selection of field in inner class when outer class and super class have a relevant filed named the same > ------- Comment #1 from tromey at gcc dot gnu dot org 2007-07-05 17:31 ------- > I tried this with svn trunk and got 'false'. > If there is a bug here it is in ecj, not gcj. Wow, that is interesting. Which ecj version are you using? v_686_R32x, 3.2.2 release gives "true". > I'm not sure I agree with your interpretation here. > I don't see how specificity applies. Isn't that term only used > for overload resolution? It's been a while since I was completely > familiar with the JLS, though ... where are you reading? I am using the completely wrong terms, sorry about that. I got the idea from JLS second edition 8.3 Field Declarations (but admit to not have had it handy when I filed the bug report, it actually took me some time to find it back): http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#40898 If the class declares a field with a certain name, then the declaration of that field is said to hide any and all accessible declarations of fields with the same name in superclasses, and superinterfaces of the class. The field declaration also shadows (§6.3.1) declarations of any accessible fields in enclosing classes or interfaces, and any local variables, formal method parameters, and exception handler parameters with the same name in any enclosing blocks. If a field declaration hides the declaration of another field, the two fields need not have the same type. A class inherits from its direct superclass and direct superinterfaces all the non-private fields of the superclass and superinterfaces that are both accessible to code in the class and not hidden by a declaration in the class. Since it mentions that the field declaration shadows the local variables of the enclosing block (the method) and not the enclosing class and that it inherits the fields (which I take to mean also shadows) I believe my interpretation is correct. > IMO the JLS could be clearer here, but I believe the local 'o' > shadows the field a.o. See: > > http://java.sun.com/docs/books/jls/third_edition/html/names.html#34133 > > Anyway, I suggest filing against ecj or perhaps the JDK for resolution. Yeah, it certainly is confusing. I need all my language lawyer skills to even defend my bug report :) All I really want is a big fat warning from the compiler for this type of usage because it clearly is something that takes a long debate to even see who is right and why. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32638 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-07-05 18:34 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2007-07-05 17:12 [Bug java/32638] New: Wrong selection of field in inner class when outer class and super class have a relevant filed named the same mark at gcc dot gnu dot org 2007-07-05 17:31 ` [Bug java/32638] " tromey at gcc dot gnu dot org 2007-07-05 18:34 ` mark at klomp 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).