[jira] [Commented] (GROOVY-6882) STC: AIC cannot resolve overridden method of outer class

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-6882) STC: AIC cannot resolve overridden method of outer class

Eric Milles (Jira)

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

Eric Milles commented on GROOVY-6882:
-------------------------------------

{code:groovy}
class B {
  void m() {
    println 'B'
  }
}

@groovy.transform.TypeChecked
class C extends B {
  @Override
  void m() {
    println 'C'
  }

  void test() {
    def x = new Runnable() {
      @Override
      void run() {
        m() // Reference to method is ambiguous. Cannot choose between [void C#m(), void B#m()]
      }
    }
    x.run()
    m()
  }
}

new C().test()
{code}

Should print "C" twice.

> STC: AIC cannot resolve overridden method of outer class
> --------------------------------------------------------
>
>                 Key: GROOVY-6882
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6882
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.0-rc-1
>            Reporter: C├ędric Champeau
>            Assignee: Eric Milles
>            Priority: Major
>
> Originally reported on StackOverflow: http://stackoverflow.com/questions/24321109/is-threre-any-way-to-ues-override-method-in-anonymous-class-on-groovy-compilest
> This fails with an ambiguous method error:
> {code}
> import groovy.transform.CompileStatic;
> interface HelloWorld {
>     public void greet();
> }
> class HelloWorldAnonymousClassesParents {
>     public void hi() {
>         println "hi"
>     }
> }
> @CompileStatic
> public class HelloWorldAnonymousClasses extends HelloWorldAnonymousClassesParents {
>     public void hi() {
>         System.out.println("hihi ");
>     }
>     public void sayHello() {
>         HelloWorld spanishGreeting = new HelloWorld() {
>             public void greet() {
>                 hi() //<- here [Static type checking] - Reference to method is ambiguous error
>                 System.out.println("spanishGreeting");
>             }
>         };
>         spanishGreeting.greet();
>         hi()
>     }
> }
> def myApp = new HelloWorldAnonymousClasses();
> myApp.sayHello();
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)