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

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

eric-milles opened a new pull request, #2316:
URL: https://github.com/apache/groovy/pull/2316

   Prevent ambiguous or unexpected dynamic dispatch by setting method target 
for trait forwarder methods.
   
   ```groovy
   trait A {
     def foo(Map<String, Object> m) {
       println("foo(m)")
     }
     def foo(Object o) {
       println("foo(o)")
     }
   }
   class B implements A {
     def bar(Map<String, Object> m) {
       println("bar(m)")
     }
     def bar(Object o) {
       println("bar(o)")
     }
     /*
     @TraitBridge(traitClass=Foo, desc="...")
     Object foo(Object o) {
       Foo$Trait$Helper.foo(this, o) // HERE
     }
     @TraitBridge(traitClass=Foo, desc="...")
     Object foo(Map<String, Object> m) {
       Foo$Trait$Helper.foo(this, m) // HERE
     }
     */
   }
   
   new B().with {
     foo((Object) null)
     foo(null as Object)
     bar((Object) null)
     bar(null as Object)
   }
   
   (new Object() as A).with {
     foo((Object) null)
     foo(null as Object)
   }
   ```




> Overload resolution of trait methods does not work properly
> -----------------------------------------------------------
>
>                 Key: GROOVY-11776
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11776
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.23, 4.0.26, 3.0.25, 5.0.1
>            Reporter: Björn Kautler
>            Assignee: Eric Milles
>            Priority: Major
>
> Given this snippet:
> {code:groovy}
> trait Foo {
>   def foo(Object o) {
>     println("foo(o)")
>   }
>   def foo(Map<String, Object> m) {
>     println("foo(m)")
>   }
> }
> class Bar implements Foo {
>   def bar(Object o) {
>     println("bar(o)")
>   }
>   def bar(Map<String, Object> m) {
>     println("bar(m)")
>   }
> }
> new Bar().with {
>   foo((Object) null)
>   foo(null as Object)
>   bar((Object) null)
>   bar(null as Object)
> }
> (new Object() as Foo).with {
>   foo((Object) null)
>   foo(null as Object)
> }
> {code}
> In Groovy 2.5, 3.0 and 4.0 {{bar}} uses the {{Object}} variant as expected, 
> but {{foo}} uses the {{Map}} variant for some reason.
> In Groovy 5.0.alpha that is still on groovyconsole.dev this was fixed and 
> both used the {{Object}} variant as expected.
> In 5.0.1 this is also broken again, behaving like before.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to