Kipper icon indicating copy to clipboard operation
Kipper copied to clipboard

[Dev Bug] Interface methods with params and retrun type other than `void` can not be implemented using object properties

Open Luna-Klatzer opened this issue 7 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

I am following the documentation's guide

  • [X] I have read the documentation

This issue exists in the latest version

  • [X] I am using the latest version

Current Behavior

Interface methods can not be implemented using object properties when the declared method has any parameters or a return type other than void i.e. is different to the default func type Func/Func<void>.

interface X {
  fun: Func<num, num>; // <- property function
  mul(a: num, b: num): num; // <- method declarator
}
var x: X = {
  fun: (a: num): num -> a + 1,
  mul: (a: num, b: num): num -> a * b, // <-- fails
};
print(x.fun(1)); // -> 2
print(x.mul(2, 2)); // <- fails

If you now change the method to be empty:

interface X {
  mul(): void; // <- method declarator
}
var x: X = {
  mul: (): void -> print("x"), // <-- works now
};
x.mul(); // <- works

Expected Behavior

  • Interfaces should allow the definition of a method with any given param and any return type.

Steps To Reproduce

  1. Declare an interface with a method that has any parameter or any return type other than void.
  2. Define the declared method using a standard property assignment expression inside an object.
  3. View error in compiler.

Environment

  • Kipper: v0.12.0-alpha.2
  • Environment: Node.js v18.18.2
  • Operating System: ArchLinux

Luna-Klatzer avatar Jul 25 '24 08:07 Luna-Klatzer