-
Notifications
You must be signed in to change notification settings - Fork 170
Disallow parameter (argument) redefinition #1784
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
Comments
For a comparison, in Fortran this: integer function f(x) result(y)
integer, intent(in) :: x
x = 2
y = x*x
end function is not allowed: $ gfortran a.f90
a.f90:3:0:
3 | x = 2
|
Error: Dummy argument 'x' with INTENT(IN) in variable definition context (assignment) at (1)
$ lfortran a.f90
semantic error: Cannot assign to an intent(in) variable `x`
--> a.f90:3:1
|
3 | x = 2
| ^ |
It seems that the example from lpython import i32
def f(x: i32) -> i32:
x = 2
return x * x
print(f(3)) # => 4 works in $ python examples/expr2.py
4 Also, I think assignment to function parameter is allowed in $ cat examples/expr2.cpp
#include <iostream>
int f(int x) {
x = 2;
return x * x;
}
int main() {
std::cout << f(3) << std::endl;
}
$ g++ examples/expr2.cpp -o expr2cpp
$ ./expr2cpp
4 Thus, it seems assignment to function parameter could be allowed in |
I shared a concern here #1803 (comment). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently this is allowed:
But we should give a compile time error message "input parameter
x
cannot be assigned to"The text was updated successfully, but these errors were encountered: