shiika-lang / shiika

A statically-typed programming language
MIT License
224 stars 15 forks source link

methods defined in sk can't be called #530

Closed aisk closed 10 months ago

aisk commented 10 months ago

Add a test .sk file:

module Foo
    def bar() -> String
        "foobar"
    end
end

Also includes it in index.sk. Then calling it like:

puts Foo.bar

Then got the shiika compile error:

Error: Error: method MethodFirstname("bar") not found on TypeFullname("Meta:Foo")
   ╭─[examples/hello.sk:3:9]
   │
 3 │ puts Foo.bar
   │         ──┬─
   │           ╰─── method MethodFirstname("bar") not found on TypeFullname("Meta:Foo")
───╯
yhara commented 10 months ago

How about this? You need self. to be called as Foo.bar (same as Ruby.)

module Foo
    def self.bar() -> String
        "foobar"
    end
end
aisk commented 10 months ago

Sorry, I'm not familiar with Ruby before, it worked now with your corrected version of codes.