nhatminhle / cofoja

Contracts for Java
GNU Lesser General Public License v3.0
151 stars 18 forks source link

incompatible types when compiling annotation with a default annotation #28

Closed nhatminhle closed 9 years ago

nhatminhle commented 9 years ago

From ksha...@broadinstitute.org on May 23, 2011 10:21:26

What steps will reproduce the problem? 1. Create an interface that uses another interface as a default. For example you can put these two lines in a file, say TestAnnotations.java:

@interface A {} @interface B {A value() default @A;}

  1. Compile without cofoja and don't get an error:

    $ javac TestAnnotations.java $

  2. Compile with cofoja and get an error:

    $ javac -cp cofoja-1.0- r126 .jar TestAnnotations.java TestAnnotations.java:2: incompatible types found : A required: A @interface B {A value() default @A;} ^ 1 error $

    (in monospace the "^" is pointing at the "A" in "@A;") What is the expected output? What do you see instead? Do not expect to have a compilation error. What version of the product are you using? On what operating system? cofoja-1.0- r126 .jar

    java version "1.6.0_22" Java(TM) SE Runtime Environment (build 1.6.0_22-b04-307-10M3261) Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03-307, mixed mode) System Version: Mac OS X 10.6.6 (10J567) Kernel Version: Darwin 10.6.0 64-bit Kernel and Extensions: No

    -and-

    javac 1.6.0_21 GNU/Linux 2.6.18-194.8.1.el5 Please provide any additional information below.

Original issue: http://code.google.com/p/cofoja/issues/detail?id=24

nhatminhle commented 9 years ago

From nhat.min...@gmail.com on May 23, 2011 12:21:41

Hi,

Thanks for reporting. This is an interesting problem but it seems to be an issue with javac, not Cofoja. Actually, any annotation processor will trigger that error. E.g. the following empty annotation processor will also produce that behavior, though it does nothing. Also, it does not happen under javac 1.7.

import java.util.; import javax.annotation.processing.; import javax.lang.model.; import javax.lang.model.element.;

@SupportedAnnotationTypes("dumb.Annotation") @SupportedSourceVersion(SourceVersion.RELEASE_6) public class DumbAnnotationProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { return false; } }

A workaround for this situation is to compile in two passes: -proc:none for your sources and -proc:only for Cofoja; it seems to work even for javac 1.6. Actually, based on feedback, I think that due to the many subtle issues that arise when processing both source and contracts at the same time (no -proc option; it does work but has some caveats, aside from this weird error), we will be recommending separate -proc:none and -proc:only passes for Cofoja in the future whenever possible.

Cc: davidmor...@google.com chat...@google.com

nhatminhle commented 9 years ago

From chat...@google.com on July 25, 2011 08:43:12

I'm closing this issue.

Status: Done
Cc: -davidmor...@google.com -chat...@google.com