Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334516 - [compiler] Reference to Outer.this should be a compile error in static context
Summary: [compiler] Reference to Outer.this should be a compile error in static context
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-17 09:47 EST by Markus Keller CLA
Modified: 2020-01-05 09:34 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2011-01-17 09:47:58 EST
HEAD

A reference to Outer.this should be a compile error in a static context, even if the instance is not actually used because a static method is called:

package p;
public class Outer {
    public static void bar() {
        new Object() {
            public void foo() {
                Outer.this.bar();// Only warns about non-static access to bar,
                                 // but 'Foo.this' should be a compile error.

                getOuter().bar();// Correct compile error.
            }
        }.toString();
    }

    Outer getOuter() {
        return new Outer();
    }
}
Comment 1 Olivier Thomann CLA 2011-01-17 11:21:37 EST
I'll take a look.
Comment 2 Olivier Thomann CLA 2011-01-17 13:29:11 EST
I think we have two issues there.
1) We don't report an error for this case until code generation. This seems to be done on purpose in the QualifiedThisReference resolveType(..) code.
2) In this case we don't report an error, because we report it only if we generate the code with valueRequired set to true.
See org.eclipse.jdt.internal.compiler.ast.MessageSend line 149.

One way to fix (2) would be to pass valueRequired set to true and pop the value. This would report the error if there is not a second error in the same method.

(1) means that this error is not reported as long as there is already another error in the same method. When a second error is reported, the code generation for this method is never reached as it is converted to a problem method (when compiled with -proceedOnError) or simply dropped.

Srikanth, if we want to improve this, we should report the error inside the resolveType(..) method or find a better location to do so. To fix (1), we need to find a location inside the type resolution.

For (2), if we fix (1), then there is no more issue. If we don't want to fix (1),l then maybe we should resolve the emulation path regardless of the value required flag.

I'll let you consider these two options.
Thanks.
Comment 3 Eclipse Genie CLA 2020-01-05 09:34:23 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.