Bug 540631 - [1.8] wrong classification of name in name::new
Summary: [1.8] wrong classification of name in name::new
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.10 M3   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-30 14:58 EDT by Stephan Herrmann CLA
Modified: 2018-11-21 03:05 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2018-10-30 14:58:50 EDT
(In reply to Greg Woolsey from bug 484467 comment #3)
> [...]
> Note that the same error happens when the Test class is moved to its own
> source file in the same package.  In that case, it appears the Eclipse
> compiler is confusing the enum with the same name vs. the class with that
> name.  However, the ::new reference must be to a type, not an Enum instance,
> which is how javac knows which one to reference. 
> 
> A workaround is to reference the class in the ::new constructor argument
> with its fully qualified class name.  Then the Eclipse compiler understands
> which "Test" is being referenced.  However, javac shows this is not
> required, and that the source ordering used by Eclipse is not flexible
> enough to handle this case and the original case for this bug.
> 
> public enum EclipseCompileBug {
> 	/*
> 	 * Next line fails with these errors in Eclipse, works with javac:
> 	 * <li>Test cannot be resolved to a type
> 	 * <li>Cannot reference a field before it is defined
> 	 */
> 	Test(Test::new);
> 
> 	@FunctionalInterface
>     public interface IConstructor<T extends Object> {
>         T apply();
>     }
> 
>     private final IConstructor<?> constructor;
> 	private EclipseCompileBug (IConstructor<?> newObj) {
> 		constructor = newObj;
> 	}
> 	
> 	public static class Test {
> 		
> 	}
> }
Comment 1 Eclipse Genie CLA 2018-10-30 15:06:29 EDT
New Gerrit change created: https://git.eclipse.org/r/131673
Comment 2 Stephan Herrmann CLA 2018-10-30 15:22:08 EDT
(In reply to Eclipse Genie from comment #1)
> New Gerrit change created: https://git.eclipse.org/r/131673

Your analysis was correct: in Name::new we should never even try to resolve Name to a variable. The parser just needs to delete one bit and all should be fine.

To wit, the relevant part of the grammar in JLS ยง15.13 is:

MethodReference:
  [...]
  ClassType :: [TypeArguments] new
  ArrayType :: new
Comment 4 Stephan Herrmann CLA 2018-10-30 19:09:09 EDT
(In reply to Eclipse Genie from comment #3)
> Gerrit change https://git.eclipse.org/r/131673 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=1d1468f56bf9e54149c9b9759e0d4e70fd0d999b

Released for 4.10 M3
Comment 5 Eclipse Genie CLA 2018-11-11 06:56:20 EST
New Gerrit change created: https://git.eclipse.org/r/132245
Comment 6 Jay Arthanareeswaran CLA 2018-11-21 03:05:13 EST
Verified for 4.10 M3 with build id I20181120-1800