This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Odd error complaint about overloaded method signatures when args have default values

2 replies
Ken McDonald
Joined: 2011-02-13,
User offline. Last seen 42 years 45 weeks ago.
For brevity, I'll just give the class and method signatures:
class TextMark { /** Insert a new substring before or after this mark. */
def insert(str: String, before: Boolean = true)
/** Insert a new mark adjacent to this one and return the new mark. */ def insert(mark: TextMark, before: Boolean = true): TextMark = {...}}
When I try to run a test, I get a compile error:
[error] /Users/Ken/Documents/Programming/Scala/contextual/src/main/scala/com/digitaldoodles/contextual/model/Text.scala:70: in class TextMark, multiple overloaded alternatives of method insert define default arguments.[error] class TextMark {
I could understand the problem if the first args had the same type and it was the second args that had differing types, because then the compiler would have no way of knowing which method to call if the optional second arg wasn't provided. But in this case, an invocation of "insert" will always be type-unambiguous. Am I missing something here?
Thanks,Ken
Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Odd error complaint about overloaded method signatures when

On Sun, May 22, 2011 at 6:13 PM, Ken McDonald wrote:
> I could understand the problem if the first args had the same type and it
> was the second args that had differing types, because then the compiler
> would have no way of knowing which method to call if the optional second arg
> wasn't provided. But in this case, an invocation of "insert" will always be
> type-unambiguous. Am I missing something here?

http://stackoverflow.com/questions/4652095/why-does-the-scala-compiler-d...

Ken McDonald
Joined: 2011-02-13,
User offline. Last seen 42 years 45 weeks ago.
Re: Odd error complaint about overloaded method signatures when
Thanks for pointing that out. I'm always amazed at how some people can just retain memories of bits of data like this--I certainly can't.
Ken

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland