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

[jira] [Comment Edited] (GROOVY-7416) Problem With CompileStatic And Interface Methods In Abstract Subclass

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

Allen Arakaki edited comment on GROOVY-7416 at 5/30/15 3:04 AM:
----------------------------------------------------------------

I've created all the cases that I think should work for interfaces/traits:

{code}
abstract class ABaseClass implements SomeInterface, SomeTrait, TraitWithSomeOtherInterface {

}
abstract class ASubClass extends ABaseClass {
  void someMethod() { 
    someInterfaceMethod() 
    someTraitMethod() 
    someOtherInterfaceMethod() 
  }
}
interface SomeInterface { 
  void someInterfaceMethod() 
}
interface SomeOtherInterface { 
  void someOtherInterfaceMethod() 
}
trait SomeTrait { 
  abstract void someTraitMethod() 
}
trait TraitWithSomeOtherInterface implements SomeOtherInterface {

}
{code}


was (Author: ikakara):
I've created all the cases that I think should work for interfaces/traits:

abstract class ABaseClass implements SomeInterface, SomeTrait, TraitWithSomeOtherInterface {}
abstract class ASubClass extends ABaseClass {
  void someMethod() {
    someInterfaceMethod()
    someTraitMethod()
    someOtherInterfaceMethod()
  }
}
interface SomeInterface {
  void someInterfaceMethod()
}
interface SomeOtherInterface {
  void someOtherInterfaceMethod()
}
trait SomeTrait {
  abstract void someTraitMethod()
}
trait TraitWithSomeOtherInterface implements SomeOtherInterface {
}


> Problem With CompileStatic And Interface Methods In Abstract Subclass
> ---------------------------------------------------------------------
>
>                 Key: GROOVY-7416
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7416
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.3
>            Reporter: Jeff Scott Brown
>         Attachments: abstractcompilestatic.zip, abstractcompilestatic.zip, abstractcompilestatic.zip, abstractcompilestatic.zip
>
>
> The attached abstractcompilestatic.zip contains the following:
> {code:borderStyle=solid|title=src/main/groovy/demo/SomeInterface.groovy}
> package demo
> interface SomeInterface {
>     void someInterfaceMethod()
> }
> {code}
> {code:borderStyle=solid|title=src/main/groovy/demo/AbstractSuperClass.groovy}
> package demo
> abstract class AbstractSuperClass implements SomeInterface {}
> {code}
> {code:borderStyle=solid|title=src/main/groovy/demo/AbstractSubClass.groovy}
> package demo
> import groovy.transform.CompileStatic
> @CompileStatic
> abstract class AbstractSubClass extends AbstractSuperClass {
>     void someMethod() {
>         someInterfaceMethod()
>     }
> }
> {code}
> The code will not compile.
> {noformat}
>  $ ./gradlew clean compileGroovy
> :clean
> :compileJava UP-TO-DATE
> :compileGroovy
> startup failed:
> /Users/jeff/abstractcompilestatic/src/main/groovy/demo/AbstractSubClass.groovy: 9: [Static type checking] - Cannot find matching method demo.AbstractSubClass#someInterfaceMethod(). Please check if the declared type is right and if the method exists.
>  @ line 9, column 9.
>            someInterfaceMethod()
>            ^
> 1 error
> :compileGroovy FAILED
> FAILURE: Build failed with an exception.
> * What went wrong:
> Execution failed for task ':compileGroovy'.
> > Compilation failed; see the compiler error output for details.
> * Try:
> Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
> BUILD FAILED
> Total time: 4.045 secs
> {noformat}
> If the AbstractSubClass is modified to implement the interface as shown below the code will compile:
> {code:borderStyle=solid|title=src/main/groovy/demo/AbstractSubClass.groovy}
> package demo
> import groovy.transform.CompileStatic
> @CompileStatic
> abstract class AbstractSubClass extends AbstractSuperClass implements SomeInterface {
>     void someMethod() {
>         someInterfaceMethod()
>     }
> }
> {code}



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