[ https://issues.apache.org/jira/browse/GROOVY-7011?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14979645#comment-14979645 ]
Dimitar Dimitrov commented on GROOVY-7011: ------------------------------------------ This was closed and currently the compiler issues an error. Is there a reason why it is not possible to just generate the overloads? i.e. being able to write this: {code} MessageValue await(String description='', MessageValue pattern=lastSent.get()) { ... } {code} instead of: {code} MessageValue await() { await '', null } MessageValue await(String description) { await description, null } MessageValue await(MessageValue<ICommand> pattern) { await '', pattern } MessageValue await(String description, MessageValue pattern) { ...(description, pattern ?: lastSent.get()) } {code} > Trait methods with default arguments do not work correctly > ---------------------------------------------------------- > > Key: GROOVY-7011 > URL: https://issues.apache.org/jira/browse/GROOVY-7011 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.3.6 > Environment: OSX 10.9, Java 1.7_67 > Reporter: Aaron Long > Assignee: Cédric Champeau > Fix For: 2.3.10, 2.4.0-rc-1 > > > The following code: > {code} > trait HiSupport { > def sayHi(String msg = "hi") { > println msg > } > } > class A implements HiSupport { } > new A().sayHi() > {code} > Produces incorrect results. The trait method is called without any > dispatching complaints, however it just ignores the default argument. > If default arguments are not supported, it seems like it should be a compile > failure or at least a failure during dispatch. > If the trait method has multiple arguments, the method dispatch does result > in a failure: > {code} > trait HiSupport { > def sayHi(String name, String msg = "hi") { > println msg + name > } > } > class A implements HiSupport { } > new A().sayHi("Bob") > {code} > {code} > groovy.lang.MissingMethodException: No signature of method: A.sayHi() is > applicable for argument types: (java.lang.String) values: [Bob] > Possible solutions: sayHi(java.lang.String, java.lang.String), wait(), any(), > each(groovy.lang.Closure), asType(java.lang.Class), wait(long) > at ConsoleScript50.run(ConsoleScript50:9) > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)