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
nothing better was found but I don't like that a lot.

Alex

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane