You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/02/01 23:19:04 UTC

[jira] [Closed] (GROOVY-5396) Groovy classes can't see package-local properties from a super class

     [ https://issues.apache.org/jira/browse/GROOVY-5396?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-5396.
-----------------------------

> 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
>             Fix For: 2.4.8
>
>         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.15#6346)