Alex Tkachman | 24 Jun 13:56

[groovy-dev] interesting bug

1st of all I am sorry for my last commit, which broke trunk. I don't
know why I thought that I've run full test suite before commit.

Now about nature of the problem.

Groovy-2138 asks for DGM method Object#plus(String) is needed, which
seems to be very natural. So I implemented Object#plus(CharSecuence)
and wrote simple test

      def x = new Object()
      assertEquals ("${x}239".toString(),  x + "239")
      assertEquals ("239${x}777".toString(), "239" + x + 777)
      assertEquals ("${x}Builder${x}".toString(), x + new
StringBuilder("Builder") + x)

But they life is not so simple.

We have GString GString#plus(String) which clashes because interfaces
has preferences to inheritance in Groovy.

We also have List#plus(Object) which also clashes when called with
String parameter.

So far I reverted my fix and reopen the issue but here are 2 questions:

1) Specific one: what is right way to implement this particular
functionality. Or is it any cheap way to implement it.

2) General one: how to approach such situations in general? I can
imagine checking meta class and doing default operation only if
(Continue reading)

Jochen Theodorou | 26 Jun 11:56

Re: [groovy-dev] interesting bug

Alex Tkachman schrieb:
> 1st of all I am sorry for my last commit, which broke trunk. I don't
> know why I thought that I've run full test suite before commit.
> 
> Now about nature of the problem.
> 
> Groovy-2138 asks for DGM method Object#plus(String) is needed, which
> seems to be very natural. So I implemented Object#plus(CharSecuence)
> and wrote simple test
> 
>       def x = new Object()
>       assertEquals ("${x}239".toString(),  x + "239")
>       assertEquals ("239${x}777".toString(), "239" + x + 777)
>       assertEquals ("${x}Builder${x}".toString(), x + new
> StringBuilder("Builder") + x)
> 
> But they life is not so simple.
> 
> We have GString GString#plus(String) which clashes because interfaces
> has preferences to inheritance in Groovy.

that sounds not quite right...GString#plus(String) called with a String 
should not call Object#plus(CharSecuence). You are saying this is the case?

Btw, the code for single argument dispatching is different from the code 
for multiple argument dispatching, it is quite possible, that the single 
argument dispatching has one or two not yet discovered problems.

> We also have List#plus(Object) which also clashes when called with
> String parameter.
(Continue reading)


Gmane