You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2015/10/13 20:29:06 UTC

[jira] [Commented] (GROOVY-6888) Static type checking fails if I change the closure input parameter name

    [ https://issues.apache.org/jira/browse/GROOVY-6888?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14955420#comment-14955420 ] 

Shil Sinha commented on GROOVY-6888:
------------------------------------

Compilation fails even if there's one declared parameter with name 'it'. There appear to be a couple different issues:

1. StaticTypeCheckingVisitor.inferSAMType does not correctly infer the parameter types for the CLOSURE_ARGUMENTS metadata to be set on the closure expression; since there are a nonzero number of declared parameters, it's type is taken to be the type of the parameter, which is Object. 

2. When determining a variable parameter's type within a closure, StaticTypeCheckingVisitor.getType doesn't use the CLOSURE_ARGUMENTS metadata unless the variable's name is "it".

> Static type checking fails if I change the closure input parameter name
> -----------------------------------------------------------------------
>
>                 Key: GROOVY-6888
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6888
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.3.3, 2.4.0-beta-1, 2.4.0-rc-1
>            Reporter: Mauro Molinari
>            Assignee: Cédric Champeau
>
> Consider the following:
> {code}
> @TypeChecked
> class A {
>   @Bindable
>   String foo
>   
>   static void main(String[] args) {
> 	  A a = new A()
> 	  a.foo = 'old'
> 	  a.addPropertyChangeListener('foo') { event ->
> 		  println 'foo changed: ' + event.oldValue + ' -> ' + event.newValue
> 	  }
> 	  a.foo = 'new'
>   }
> }
> {code}
> The Groovy compiler fails:
> bq. [Static type checking] - No such property: oldValue for class: java.lang.Object
> This is unexpected, because if I leave the {{event}} naming of the closure input parameter and use {{it.oldValue}}/{{it.newValue}} the static type checking succeeds (as it should).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)