Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 391196 - [1.8][compiler] Compiler rejects type annotations in valid locations
Summary: [1.8][compiler] Compiler rejects type annotations in valid locations
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-05 03:43 EDT by Srikanth Sankaran CLA
Modified: 2012-10-09 10:44 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2012-10-05 03:43:39 EDT
BETA_JAVA8:

The following program should compile, but does not. (note that javac also
erroneously reports one error, while we report 2 more):

// ----
@Marker public class X {
	@Marker public int foo(){
		Object o = (@Marker String) null;
	}
}

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

Per EDR section 2.3:

"A type annotation (one meta-annotated with @Target(ElementType.TYPE USE)) 
is permitted to be written anywhere @Target(ElementType.TYPE) or 
@Target(ElementType.TYPE PARAMETER) would permit—that is, on a class,
interface, or enum declaration, or on a type parameter declaration."

Also

"A type annotation may appear before a constructor, in which case it 
represents the object that the constructor is creating (which is not 
the same as the receiver of the constructor)."

Fix should go in org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(BlockScope)
Comment 1 Srikanth Sankaran CLA 2012-10-05 03:45:20 EDT
The snippet should be:

// ----
@Marker 
public class X<@Marker T> {
	@Marker X() {
	}
}

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

and not the case in comment#0
Comment 2 Jay Arthanareeswaran CLA 2012-10-09 10:44:44 EDT
Fixed along with the fix for bug 391201 via commit:

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