Re: [ceylon-dev] Error when calling an overloading toString method of a java class

50 views
Skip to first unread message

Gavin King

unread,
Dec 19, 2012, 6:34:14 PM12/19/12
to ceylo...@googlegroups.com, ceylo...@googlegroups.com
Eek, I don't think we've seen this one before, I suppose you should report it in the GitHub issue tracker. Probably belongs in ceylon-compiler though its possible it also affects the type checker.

Sent from my iPhone

On 19/12/2012, at 11:15 PM, Loïc Rouchon <loic.r...@gmail.com> wrote:

Hello,

I just discover Ceylon after the nice talk of Stéphane at the Riviera JUG and I found this language really nice.

So I start to play with it and I'm currently trying to do a server-side REST application just to see how it would look in Ceylon.
I read the tour and docs I found on the site and I started a test project using io.netty '3.5.0.Final' for the http server part.

I'm able to receive requests and to reply, but I'm having a little issue when trying to convert the HTTP message body Buffer into a String

I'm getting the input buffer using org.jboss.netty.handler.codec.http.HttpRequest.content
It is of type org.jboss.netty.buffer.ChannelBuffer

When I look at the documentation of that interface, there is several toString() overloaded methods to convert the buffer to a string
http://static.netty.io/3.5/api/org/jboss/netty/buffer/ChannelBuffer.html#toString%28java.lang.String%29

So I decide to use the simplest one for my test which is:
String toString(String charsetName) (it is a deprecated one but I'd like to stay simple to start)

My call is written as below:
return buffer.string("UTF-8");
But when I compile, I have the following error raised by the compiler:
.../test/source/main/HttpServerHandler.ceylon:62: error: invoked expression must be callable: String is not a subtype of Callable
return buffer.string("UTF-8");


Which seems normal as string is an attribute
in ceylon.
Si I tried to see if using an alias in the import would solve the issue.

import org.jboss.netty.buffer { ChannelBuffer {convertToString=toString} }
and change my call to:
return buffer.convertToString("UTF-8");
And the compilation output:
.../test/source/main/HttpServerHandler.ceylon:63: error: cannot find symbol
        return buffer.convertToString("UTF-8");
               ^
  symbol:   method $toString(String)
  location: variable buffer of type ChannelBuffer


For information, in eclipse, I have a compile error with both notations but with the second one, on a mouse over the method call, the following declaration is found by eclipse:
formal String toString(String? string)
which looks pretty good

I'm using ceylon 0.4


I don't know if I'm missing something or if there is a bug in the interop with java toString() overloaded methods

If it is a bug, just tell me and I will open a bug report for it.


I'm using ceylon 0.4

Regards,
Loic

--
You received this message because you are subscribed to the Google Groups "ceylon-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ceylon-dev/-/l04EHnMFgKYJ.
To post to this group, send email to ceylo...@googlegroups.com.
To unsubscribe from this group, send email to ceylon-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ceylon-dev?hl=en.

Stephane Epardaud

unread,
Dec 20, 2012, 4:52:29 AM12/20/12
to ceylon-dev
This is likely a JVM compiler backend bug.

Could you report it at https://github.com/ceylon/ceylon-compiler/issues/new and we'll fix it ASAP?

Thanks
--
Stéphane Épardaud

Stephane Epardaud

unread,
Dec 20, 2012, 6:27:06 AM12/20/12
to ceylon-dev
I reported it at https://github.com/ceylon/ceylon-compiler/issues/932 (and fixed it) and https://github.com/ceylon/ceylon-spec/issues/509

Now your problem is going to be that the fix is for M5, so you won't be able to do this until we release it. Your best workaround is to create a Java class that does the right toString call for you and you use it from your Ceylon code.
--
Stéphane Épardaud

Loïc Rouchon

unread,
Dec 20, 2012, 8:39:33 AM12/20/12
to ceylo...@googlegroups.com
Thank you for the quick reply and really quick report + fix.

I don't know what I will do to make it work on my side, maybe instead of the proposed workaround, I will try to use the current development version

Thanks
Reply all
Reply to author
Forward
0 new messages