Hello,

With the new Groovy 3.0.0, and 3.0.0-rc-3, which I though I were using but 
weren't (were actually using 3.0.0-beta-3 which works fine) there is a 
compilation problem. 

I get the following errors, actually the same error in 2 different places (I'm 
on a Mac and have used Menlo font for code parts, don't know how/if that 
translates to other platforms):
Error:(182, 9) Groovyc: [Static type checking] - Cannot call 
se.natusoft.osgi.aps.api.messaging.APSBus#send(java.lang.String, java.util.Map 
<java.lang.String, java.lang.Object>, se.natusoft.osgi.aps.types.APSHandler 
<se.natusoft.osgi.aps.types.APSResult>) with arguments [java.lang.String, 
java.util.Map <String, Object>, se.natusoft.osgi.aps.types.APSHandler 
<APSResult>]
Error:(252, 9) Groovyc: [Static type checking] - Cannot call 
se.natusoft.osgi.aps.api.messaging.APSBus#send(java.lang.String, java.util.Map 
<java.lang.String, java.lang.Object>, se.natusoft.osgi.aps.types.APSHandler 
<se.natusoft.osgi.aps.types.APSResult>) with arguments [java.lang.String, 
java.util.Map <String, Object>, se.natusoft.osgi.aps.types.APSHandler 
<APSResult>]

Clarification by aligning args:

Error:(182, 9) Groovyc: [Static type checking] - Cannot call 
se.natusoft.osgi.aps.api.messaging.APSBus#send(

                  java.lang.String, java.util.Map <java.lang.String, 
java.lang.Object>, se.natusoft.osgi.aps.types.APSHandler 
<se.natusoft.osgi.aps.types.APSResult>) 
  
  with arguments [java.lang.String, java.util.Map <String, Object>,             
        se.natusoft.osgi.aps.types.APSHandler <APSResult>]
  

Error:(252, 9) Groovyc: [Static type checking] - Cannot call 
se.natusoft.osgi.aps.api.messaging.APSBus#send(

                  java.lang.String, java.util.Map <java.lang.String, 
java.lang.Object>, se.natusoft.osgi.aps.types.APSHandler 
<se.natusoft.osgi.aps.types.APSResult>) 
  
  with arguments [java.lang.String, java.util.Map <String, Object>,             
        se.natusoft.osgi.aps.types.APSHandler <APSResult>]

  
For method declaration it sees the generics part as "java.lang.String" and 
"java.lang.Object" but in the call it sees it as "String" and "Object". Should 
be the same thing, but clearly it doesn't see that. Here it is a total stop 
since I cannot fix these using "as" keyword to make it identical to what it 
wants, but actually already is :-). The compiler still reports the same error 
where the package part has been removed. The parameters are exactly what is 
declared and needed.

Here is the actual source code for the above 2 errors:
this.bus.send( "cluster:${serviceId}" as String, message as Map<String, 
Object>, resultHandler as APSHandler<APSResult<?>> )
this.bus.send(
        "cluster:all:${this.helperForServiceId}/announce" as String,
        new ServiceAnnounceMessage( this.helperForServiceId ) as Map<String, 
Object>,
        resultHandler as APSHandler<APSResult<?>>
)

And no, I didn't have the "as ..." part to begin with, with the exception of 
the first argument which is a GString and needs to be made into a String. But 
adding the "as" part doesn't help. But from the error message above I'd say it 
is that it looses the packages in the generics part of the actual call 
arguments that is the problem. What it expects and the real actual arguments 
are the same. 

And here is the declarations of the API in interface. It is the same method 
called in both cases. Ignore the annotations, they are just documentative.
void send( @NotNull String target, @NotNull Map<String, Object> message,
           @Optional @Nullable APSHandler<APSResult<?>> resultHandler );
The interface is written in Java! All Groovy classes uses @CompileStatic and 
@TypeChecked.


I also want to point out that for the java.util.Map<java.lang.String, 
java.lang.Object> I do pass an instance of a class that implements exactly 
that! But compiler is not happy, I have to add "as 
java.util.Map<java.lang.String, java.lang.Object>" to the argument passed!

Here is from the code:

    MessageTypeServiceHelper announceService( APSHandler<APSResult<?>> 
resultHandler ) {
        this.bus.send(
                "cluster:all:${this.helperForServiceId}/announce" as String,
                new ServiceAnnounceMessage( this.helperForServiceId ) as 
Map<String, Object>,
                resultHandler
        )
        

ServiceAnnounceMessage extends BaseMesage which is declared like this:

    class BaseMessage implements Map<String, Object> {
    
The compiler should figure that out IMHO. I should not be forced to add "as 
Map<String, Object>" here.

3.0.0-beta-3 has none of these problems. 

Best Regards,
Tommy

Reply via email to