Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type inference for functions with methods #4285

Open
toots opened this issue Dec 24, 2024 Discussed in #4284 · 0 comments
Open

Type inference for functions with methods #4285

toots opened this issue Dec 24, 2024 Discussed in #4284 · 0 comments
Assignees

Comments

@toots
Copy link
Member

toots commented Dec 24, 2024

See: #4284

Originally posted by martinkirch December 24, 2024
Using v2.3, I'm trying to implement a function able to check and update the given reference. A simplified version looks like:

next_track = ref({title="", artist="", rid=-1, initial_uri= ""})
next_jingle = ref({title="", artist="", rid=-1, initial_uri= ""})

def update_next_track(r)
    if r().rid != 0 then
    r := {title="bla", artist="blo", rid=0, initial_uri="http://bla"}
    end
end

update_next_track(next_track)
update_next_track(next_jingle)

but this results in a type error

line 6, char 4:
    r := {title="bla", artist="blo", rid=0, initial_uri="http://bla"}

Error 5: this value has no method `set`
  Its type is () -> 'A.{rid : int}.

I've tried to annotate the argument (r:ref or ref:ref({title:string, artist:string, rid:int, initial_uri:string})) but that raised a parse error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants