- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Odd error complaint about overloaded method signatures when args have default values
Sun, 2011-05-22, 17:13
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
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
Sun, 2011-05-22, 19:17
#2
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
Ken
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...