You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/10/13 09:17:05 UTC

[jira] [Commented] (GROOVY-7627) Property calls are not correctly type checked if the setter parameter type or getter return type are not the field type

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

ASF GitHub Bot commented on GROOVY-7627:
----------------------------------------

GitHub user shils opened a pull request:

    https://github.com/apache/incubator-groovy/pull/139

    GROOVY-7627 Property calls are not correctly type checked if the sett…

    …er parameter type or getter return type are different from the underlying field type

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/shils/incubator-groovy GROOVY-7627

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-groovy/pull/139.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #139
    
----
commit 211f7426f4fe31aa360fc48bb5af15cee6ea9e3d
Author: Shil S <sh...@gmail.com>
Date:   2015-10-13T07:03:55Z

    GROOVY-7627 Property calls are not correctly type checked if the setter parameter type or getter return type are different from the underlying field type

----


> Property calls are not correctly type checked if the setter parameter type or getter return type are not the field type
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7627
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7627
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.4.5
>         Environment: JDK 1.8.0_60
>            Reporter: Shil Sinha
>            Assignee: Cédric Champeau
>
> If a class defines a property but also explicitly provides a getter or setter, property style get/set calls are type checked using the underlying field type rather than the getter return type/setter parameter type.
> Setter example:
> {code}
> class Foo {
>     Bar bar;
>     void setBar(int x) {
>         this.bar = new Bar(x: x)
>     }
> }
> class Bar {
>     int x
> }
> @groovy.transform.TypeChecked
> void test() {
>     Foo foo = new Foo()
>     foo.bar = new Bar()
> }
> test()
> {code}
> The code above will pass STC and throw a GroovyCastException at runtime. Conversely, code like {{foo.bar = 1}} will not pass STC.  The case for getters with return type different from the field type is similar.



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