TypeChecked + CompileStatic on c-tors

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

TypeChecked + CompileStatic on c-tors

ysb33r
Can either of these two annotations be used on constructors? My
compilation is failing with

Annotation @groovy.transform.TypeChecked$TypeCheckingInfo is not allowed
on element CONSTRUCTOR
  @ line -1, column -1.

Works fine on methods within the class, just not on the c-tors.

--
Schalk W. Cronjé
@ysb33r


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: TypeChecked + CompileStatic on c-tors

Andre Steingress
Both annotations can be used on constructors, e.g.

class Test {

   Integer i

   @groovy.transform.TypeChecked
   Test(def i) {
      this.i = i
   }
}

Results in: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.lang.Integer

Your compilation errors says that groovy.transform.TypeChecked$TypeCheckingInfo can not be applied on a constructor which is true, but TypeCheckingInfo is used only internally to store the inferred method return type.

Maybe you could provide a code example where this compile error occurs?

Cheers, André
Reply | Threaded
Open this post in threaded view
|

Re: TypeChecked + CompileStatic on c-tors

ysb33r
André,

A good example is at this github code

https://github.com/ysb33r/KroovyBan/blob/master/dsl/vfs/src/main/groovy/org/ysb33r/groovy/dsl/vfs/URI.groovy

If I add either of the two annotations to the  constructor at line 73 it
fails to compile.



On 20/01/2013 08:26, Andre Steingress wrote:

> Both annotations can be used on constructors, e.g.
>
> class Test {
>
>     Integer i
>
>     @groovy.transform.TypeChecked
>     Test(def i) {
>        this.i = i
>     }
> }
>
> Results in: [Static type checking] - Cannot assign value of type
> java.lang.Object to variable of type java.lang.Integer
>
> Your compilation errors says that
> groovy.transform.TypeChecked$TypeCheckingInfo can not be applied on a
> constructor which is true, but TypeCheckingInfo is used only internally to
> store the inferred method return type.
>
> Maybe you could provide a code example where this compile error occurs?
>
> Cheers, André
>
>
>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/TypeChecked-CompileStatic-on-c-tors-tp5712521p5712522.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>


--
Schalk W. Cronjé
@ysb33r


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: TypeChecked + CompileStatic on c-tors

Andre Steingress
Wow. Actually, reproducing this issue (in 2.0.5, 2.0.6, 2.1-RCx) was fairly simple :-)

class Test {
    @groovy.transform.TypeChecked
    Test() {}
}

Here is the JIRA issue and the patch:

https://jira.codehaus.org/browse/GROOVY-5933

Cheers, André

On Sunday, January 20, 2013 at 8:30 PM, Schalk Cronj é wrote:

André,

A good example is at this github code


If I add either of the two annotations to the constructor at line 73 it
fails to compile.



On 20/01/2013 08:26, Andre Steingress wrote:
Both annotations can be used on constructors, e.g.

class Test {

Integer i

@groovy.transform.TypeChecked
Test(def i) {
this.i = i
}
}

Results in: [Static type checking] - Cannot assign value of type
java.lang.Object to variable of type java.lang.Integer

Your compilation errors says that
groovy.transform.TypeChecked$TypeCheckingInfo can not be applied on a
constructor which is true, but TypeCheckingInfo is used only internally to
store the inferred method return type.

Maybe you could provide a code example where this compile error occurs?

Cheers, André



--
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:



--
Schalk W. Cronjé
@ysb33r


---------------------------------------------------------------------
To unsubscribe from this list, please visit:


Reply | Threaded
Open this post in threaded view
|

Re: TypeChecked + CompileStatic on c-tors

Cédric Champeau
Indeed. Very surprising as our unit tests have many statically checked constructors... Very good catch!

Le 20/01/2013 21:50, Andre Steingress a écrit :
Wow. Actually, reproducing this issue (in 2.0.5, 2.0.6, 2.1-RCx) was fairly simple :-)

class Test {
    @groovy.transform.TypeChecked
    Test() {}
}

Here is the JIRA issue and the patch:


Cheers, André

On Sunday, January 20, 2013 at 8:30 PM, Schalk Cronj é wrote:

André,

A good example is at this github code


If I add either of the two annotations to the constructor at line 73 it
fails to compile.



On 20/01/2013 08:26, Andre Steingress wrote:
Both annotations can be used on constructors, e.g.

class Test {

Integer i

@groovy.transform.TypeChecked
Test(def i) {
this.i = i
}
}

Results in: [Static type checking] - Cannot assign value of type
java.lang.Object to variable of type java.lang.Integer

Your compilation errors says that
groovy.transform.TypeChecked$TypeCheckingInfo can not be applied on a
constructor which is true, but TypeCheckingInfo is used only internally to
store the inferred method return type.

Maybe you could provide a code example where this compile error occurs?

Cheers, André



--
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:



--
Schalk W. Cronjé
@ysb33r


---------------------------------------------------------------------
To unsubscribe from this list, please visit:




-- 
Cédric Champeau
SpringSource - A Division Of VMware
http://www.springsource.com/
http://twitter.com/CedricChampeau