Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 391464 - [1.8][compiler] Compiler fails to resolve annotations in a few places
Summary: [1.8][compiler] Compiler fails to resolve annotations in a few places
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: BETA J8   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 287648
  Show dependency tree
 
Reported: 2012-10-09 13:18 EDT by Srikanth Sankaran CLA
Modified: 2012-10-12 02:18 EDT (History)
0 users

See Also:
jarthana: review+


Attachments
Proposed fix (10.17 KB, patch)
2012-10-11 07:08 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Patch under consideration (19.48 KB, patch)
2012-10-11 13:39 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2012-10-09 13:18:35 EDT
BETA_JAVA8:

The following program should trigger four errors. It triggers only two:

// ------
public class X<T> {
	public void foo() {
		Object o = (X @Marker []) null;  // Error here - Good. (ArrayTypeReference)
		o = (java.lang.String @Marker []) null; // Error here - Good. (ArrayQualifiedTypeReference)
		o = (X<String> @Marker []) null; // No error here - Bad. (ParameterizedSingleTypeReference)
	    o = (java.util.List<String> @Marker []) null; // No error here, Bad. (ParameterizedQualifiedTypeReference)
		if (o == null) {
			return;
		}
	}
}

// ----
Comment 1 Jay Arthanareeswaran CLA 2012-10-11 07:08:29 EDT
Created attachment 222168 [details]
Proposed fix

Patch with tests. All Java 8 tests pass and one of the existing test had to be adjusted. Running all tests now and will report once they complete.
Comment 2 Jay Arthanareeswaran CLA 2012-10-11 09:07:35 EDT
(In reply to comment #1)
> Running all tests now and will report once they complete.

All existing tests pass too.
Comment 3 Srikanth Sankaran CLA 2012-10-11 12:19:12 EDT
Two more issues found when reviewing this patch:

- GrammarCoverageTests308#test019 is expecting wrong output.
- The following program compiles fine when it should not:

// ----
public class X  {
	class Y {
		class Z {}
	}
	
	@M X.@M Y.@Unreported Z z = null;
}


@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)
@interface M {
}

The type annotation resolution code could use a good bit of reorganization.
Patch will follow shortly.
Comment 4 Srikanth Sankaran CLA 2012-10-11 13:39:17 EDT
Created attachment 222191 [details]
Patch under consideration

Jay, please take a look - this drastically simplifies annotation resolution,
Comment 5 Srikanth Sankaran CLA 2012-10-11 13:40:57 EDT
One other problem the patch fixes is in:

Object r = @Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;

We were not resolving the annotation ahead of Entry,
Comment 6 Srikanth Sankaran CLA 2012-10-11 23:21:02 EDT
Jay, all tests pass. If you agree with the patch, please release.

Note: At this point, the TypeUseBinding objects created are not hooked
up either to the TypeReference or to the TypeBindig.
Comment 7 Jay Arthanareeswaran CLA 2012-10-12 00:42:48 EDT
(In reply to comment #5)
> One other problem the patch fixes is in:
> 
> Object r = @Marker java. @Marker util.@Marker Map<@Marker String, @Marker
> String>.@Marker Entry @Marker []) null;
> 
> We were not resolving the annotation ahead of Entry,

If the type reference in question has a problem, do we still want to resolve the annotation ahead of the type reference?
Comment 8 Srikanth Sankaran CLA 2012-10-12 01:29:31 EDT
(In reply to comment #7)

> If the type reference in question has a problem, do we still want to resolve
> the annotation ahead of the type reference?

I am OK with that. In general we should report as many errors as possible while avoiding reporting a cascade of secondary errors. By secondary errors I mean
errors that would go away if some other already reported error is addressed.

for example in:

public class X  {
@Marker List<String> l;
}

We report two errors:

- List cannot be resolved to a type
- Marker cannot be resolved to a type

Fixing the first by importing java.util.List does not resolve the latter and
it is useful to report both.

On the other hand it would not be acceptable to report that unknown
type List cannot be parameterized with <String>

What exactly do you have in mind ? Can you show me a test case ?
Comment 9 Jay Arthanareeswaran CLA 2012-10-12 02:00:10 EDT
(In reply to comment #8)
> What exactly do you have in mind ? Can you show me a test case ?

Actually, it's the same test case quoted in comment #7. Your explanation is good. Sorry for the noise.

Another question more out of curiosity:

Object r = ( java.util.Map.@Unresolved Entry<?, ?>) null;

We report a cannot-be-resolved error. The location where the annotation appears is disallowed but we are not reporting yet. Shouldn't we be reporting the disallowed error also?
Comment 10 Srikanth Sankaran CLA 2012-10-12 02:09:02 EDT
(In reply to comment #9)

> Another question more out of curiosity:
> 
> Object r = ( java.util.Map.@Unresolved Entry<?, ?>) null;
> 
> We report a cannot-be-resolved error. The location where the annotation
> appears is disallowed but we are not reporting yet. Shouldn't we be
> reporting the disallowed error also?

It is legal to annotate Entry - why do you see it is illegal ?
Comment 11 Jay Arthanareeswaran CLA 2012-10-12 02:17:43 EDT
(In reply to comment #10)
> It is legal to annotate Entry - why do you see it is illegal ?

Clearly, I am not thinking right! I meant this code, really:
  Object r = ( java.util.@MarkerAnnots Map.Entry<?, ?>) null;
But we are reporting the correct error. So, there is no problem.
Comment 12 Jay Arthanareeswaran CLA 2012-10-12 02:18:51 EDT
(In reply to comment #6)
> Jay, all tests pass. If you agree with the patch, please release.

Patch is good. Released it:

http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=108910be72e713e6e104fafacd635988e5383096