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

Reassigning function parameters breaks function calls #234

Open
YuriGen2423 opened this issue Apr 10, 2024 · 1 comment · May be fixed by #222
Open

Reassigning function parameters breaks function calls #234

YuriGen2423 opened this issue Apr 10, 2024 · 1 comment · May be fixed by #222

Comments

@YuriGen2423
Copy link

YuriGen2423 commented Apr 10, 2024

function func(x:number) {
    x = Math.floor(x)
    return x
}

print(func(Vars.ipt))
printFlush()

gives The operator '=' is not defined for [1].
expected something like:

op floor func:smth @ipt
print func:smth
printflush message1

because before it wasn't broken

@JeanJPNM
Copy link
Collaborator

This will be fixed by #222.

This is a consequence of the current implementation of function inlining, which essentially replaces the parameters in the function body by the received values, generates the mlog code and then checks if it is short enough to inline. This means that for this code:

function func(x: number) {
    x = Math.floor(x)
    return x
}

print(func(1))
printFlush()

The compiler generates this internal function to see if the generated code is short enough to be inlined:

function func__0() {
    1 = Math.floor(1)
    return 1
}

And then it sees that 1 = Math.floor(1) is an invalid assignment, so it throws an error.

@JeanJPNM JeanJPNM linked a pull request Apr 10, 2024 that will close this issue
@JeanJPNM JeanJPNM changed the title Broken "=" on functions Reassigning function parameters breaks function calls Apr 11, 2024
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

Successfully merging a pull request may close this issue.

2 participants