aardappel / lobster

The Lobster Programming Language
http://strlen.com/lobster
2.24k stars 121 forks source link

Fatal application exit when calling function of inherited class #257

Closed ValetNoir closed 1 year ago

ValetNoir commented 1 year ago

Hey ! I was trying to have a parent class contain an empty draw function, so I could overwrite it with an argument (else I couldn't, it would give me a weird error: 'de-indentation' expected, found 'indentation') in the child classes (not really useful when I think about it 🤔) and I got the "send this to the developper window".

Here is a repro case:

class Foo:
    def foo() -> void

class FooFoo: Foo
    // trying to overwrite the function
    def foo(text: string):
        print(text)

let a = Foo {}
a.foo()

// same with child class
// let a = FooFoo {}
// a.foo() // <- forget to pass an argument, calls the wrong version of the function

and the log: lobster.exe.exp.log

Thanks for taking a look 😁 !

aardappel commented 1 year ago

I will have a look at it, thanks!

Btw, in Lobster you don't even need to declare "empty" functions in the parent class, as long as you don't instantiate the parent. You could even mark the parent abstract to enforce that.

aardappel commented 1 year ago

Fixed in https://github.com/aardappel/lobster/commit/b53ef6ac7fb8a54cdc473adfb0ba8837df7e586e

def foo() -> void indeed declares a function type. The error was that it allowed a function type and a regular function to share the same name, and then when calling it, it didn't notice it was calling a type because there was also a regular function version. All of that is now disallowed :)

ValetNoir commented 1 year ago

Thanks a lot for the advices and for the fix !