Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 349054 - [1.7] Missing type arguments (diamond) of variable declaration prevent variable binding recovery
Summary: [1.7] Missing type arguments (diamond) of variable declaration prevent variab...
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: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-10 11:18 EDT by Markus Keller CLA
Modified: 2019-09-08 12:11 EDT (History)
4 users (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-06-10 11:18:54 EDT
BETA_JAVA7

The class below tries to use a diamond in a variable declaration (or just misses the type arguments). In I20110603-0909, this didn't stop the compiler from recovering a variable binding for the SimpleName 'var' (with type ArrayList<?>).

In BETA_JAVA7, only the VariableDeclarationFragment gets a binding, but the SimpleNames don't. Furthermore, the type is now a recovered type 'diamond.ArrayList'. The old inferred type was better. This is broken for both 1.5 and 1.7 compliance.


package diamond;

import java.util.ArrayList;
import java.util.List;

public class DiamondErr1 {
	List<? extends Number> m() {
		ArrayList<> var = new ArrayList<>();
		return var;
	}
}
Comment 1 Srikanth Sankaran CLA 2011-06-12 22:26:50 EDT
I'll take a look.
Comment 2 Srikanth Sankaran CLA 2011-06-14 03:51:02 EDT
Experimenting with the following program, I see the 3.7 compiler's
repair attempts rather misguided/feeble here:

import java.util.ArrayList;
import java.util.List;

public class DiamondErr1 {
    List<? extends Number> m() {
        ArrayList<> var = new ArrayList<>();
        XYZ<> var2 = new XYZ<>(); 
        return var;
    }
} 


class XYZ<T, U, V> {
	
}

XYZ<> is repaired to be XYZ<?> which results in the messages around
incorrect arity - which could in fact confuse a user more since
the messages is "Incorrect number of arguments for type XYZ<T,U,V>;
it cannot be parameterized with arguments <?>" - something that does
not correspond to source at all.

Nor does the "Cannot instantiate the type ArrayList<?>" message.

So, from a purely user-visible messages pov, BETA_JAVA7 seems to
do a better job.

Markus, what UI features/capabilities get affected by this ?

Olivier, what would you expect from the compiler AST & bindings ?
Comment 3 Markus Keller CLA 2011-06-14 10:03:47 EDT
The most visible affected UI feature is Mark Occurrences: The connection between the declaration and the reference to "var" is lost. This also means that the Local Rename quick assist doesn't work any more.

I agree that the recovery in 3.7 was also not great, but at least the local variables got proper bindings in the simple case. With multiple type parameters, this also failed in 3.7, e.g. here:

    List<? extends Number> m2() {
        XYZ<> var2 = new XYZ<>(); 
        return var2;
    }

Secondary problems are e.g. that Extract Method on
        ArrayList<> var = new ArrayList<>();
does not find anything to return, but that's minor and can be accepted in code that contains syntax errors.

Bindings-wise, I would not expect to get ITypeBindings that return true for isGenericType() here. Such bindings should only show up for a type declaration. In 3.7, I also get a genericType for "XYZ<>", but in BETA_JAVA7, I even get it on ArrayList. Ideally, the recovered binding for XYZ<> would be the parameterizedType XYZ<> or XYZ<?, ?, ?>.
Comment 4 Olivier Thomann CLA 2011-07-11 11:55:04 EDT
Srikanth, please try to see if you can accommodate Markus with what he reported in comment 3. I am not sure we can do a lot better for the binding recovery.
Comment 5 Srikanth Sankaran CLA 2011-08-08 00:33:20 EDT
Unfortunately, I don't expect to get to this in 3.7.1 timeframe.
Retargetting to 3.8.
Comment 6 Srikanth Sankaran CLA 2012-01-28 20:35:17 EST
Don't expect to get to this anytime soon. Will consider for
next release.
Comment 7 Eclipse Genie CLA 2019-09-08 12:11:22 EDT
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.