jsweet icon indicating copy to clipboard operation
jsweet copied to clipboard

Zero and single argument FunctionalInterfaces are uncallable

Open rendaw opened this issue 3 years ago • 4 comments

public class ThingA {
  static void m(Step step) {
    step.apply();
  }

  @FunctionalInterface
  public interface Step {
    void apply();
  }
}

produces the error expected 1-2 arguments, but got 0 with:

/* Generated from Java with JSweet 2.4.0-SNAPSHOT - http://www.jsweet.org */
namespace jsweettest.moda {
    export class ThingA {
        static m(step : ThingA.Step) {
            ((target => (target['apply'] === undefined)?target:target['apply'])(step))();
        }
    }
    ThingA["__class"] = "jsweettest.moda.ThingA";


    export namespace ThingA {

        export interface Step {
            ();
        }
    }

}

public class ThingA {
  static void m(Step step) {
    step.apply(4);
  }

  @FunctionalInterface
  public interface Step {
    void apply(int o1);
  }
}

produces error the 'this' context of type 'void' is not assignable to method's 'this' of type 'Function' with output:

/* Generated from Java with JSweet 2.4.0-SNAPSHOT - http://www.jsweet.org */
namespace jsweettest.moda {
    export class ThingA {
        static m(step : ThingA.Step) {
            ((target => (target['apply'] === undefined)?target:target['apply'])(step))(4);
        }
    }
    ThingA["__class"] = "jsweettest.moda.ThingA";


    export namespace ThingA {

        export interface Step {
            (o1 : number);
        }
    }

}


rendaw avatar Feb 07 '21 08:02 rendaw

I should clarify, this also happens with 2 arguments, and where the argument types are from generic arguments. I haven't tested further.

rendaw avatar Feb 07 '21 08:02 rendaw

The workaround seems to be to use Runnable/Consumer/Supplier/Function/BiConsumer/BiFunction/etc whenever possible.

rendaw avatar Feb 07 '21 08:02 rendaw

This one seems blocking to me. It should definitively work.

Thanks for reporting.

lgrignon avatar Apr 11 '21 09:04 lgrignon

Oh, I notice you are using J4TS. Do you reproduce without J4TS please?

lgrignon avatar Apr 11 '21 09:04 lgrignon