Kipper-Lang / Kipper

The Kipper programming language for Browsers and Node.js 🦊✨ Made at HTL Leonding & JKU Linz
https://kipper-lang.org
GNU General Public License v3.0
26 stars 4 forks source link

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

Open Luna-Klatzer opened 1 month ago

Luna-Klatzer commented 1 month ago

Is there an existing issue for this?

I am following the documentation's guide

This issue exists in 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

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