groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-5396) Groovy classes can't see package-local properties from a super class
Date Fri, 26 Aug 2016 00:09:21 GMT

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

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

Github user paulk-asert closed the pull request at:

    https://github.com/apache/groovy/pull/396


> Groovy classes can't see package-local properties from a super class
> --------------------------------------------------------------------
>
>                 Key: GROOVY-5396
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5396
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.0-beta-1, 1.8.6
>            Reporter: Tim Yates
>            Assignee: Paul King
>         Attachments: FailingAbstractSuper.tgz
>
>
> If I have a standard gradle project setup (attached):
> {code}
> build.gradle
> src/
>   main/
>     java/
>       test/
>         AbstractBase.java
>         SamePackageJavaBase.java
>     groovy/
>       test/
>         GroovyBase.groovy
>         GroovyBaseWithSuper.groovy
> {code}
> I have a single Abstract base class:
> {code:title=AbstractBase.java}
> package test ;
> public abstract class AbstractBase {
>   int base ;
>   public AbstractBase( int base ) {
>     this.base = base ;
>   }
>   public abstract int mult( int n ) ;
> }
> {code}
> And a class {{GroovyBase}} that extends this class:
> {code:title=GroovyBase.groovy}
> package test
> public class GroovyBase extends AbstractBase {
>   public GroovyBase( int n ) {
>     super( n )
>   }
>   public int mult( int n ) {
>     n * base
>   }
>   static main( args ) {
>     println new GroovyBase( 10 ).mult( 3 )
>   }
> }
> {code}
> When running this (using the Gradle script in the attachment), I get the exception:
> {code}
> Exception in thread "main" groovy.lang.MissingPropertyException: No such property: base
for class: test.GroovyBase
> Possible solutions: class
> {code}
> Changing the line
> {code}
>     n * base
> {code}
> to
> {code}
>     n * super.base
> {code}
> Or making the {{base}} field public in the {{AbstractBase}} class makes it work.
> It's as if the classes are considered to be in different packages for some things, but
not for others.
> Thinking about it, not sure if this is a Gradle bug or a Groovy cross compiler one.
> To run the tests, unpack the attachment, and run:
> {code}
> # Test the above failing example
> gradle -Pmain=test.GroovyBase
> # Test the addition of super.base
> gradle -Pmain=test.GroovyBaseWithSuper
> # Test the Java extension of the Abstract class
> gradle -Pmain=test.SamePackageJavaBase
> {code}
> You can change the groovy version from 1.8.6 by passing (for example) {{-Pgroovy=groovy=2.0.0-beta-2}}



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

Mime
View raw message