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

Shadowing function arguments may cause null to surface #58

Open
marad opened this issue Sep 19, 2022 · 1 comment
Open

Shadowing function arguments may cause null to surface #58

marad opened this issue Sep 19, 2022 · 1 comment
Labels
bug Something isn't working core Requires changes in core compiler code hacktoberfest Changes good for hacktoberfest

Comments

@marad
Copy link
Owner

marad commented Sep 19, 2022

Example problematic code:

fn foo(arg: int) {
  println(arg)
  val arg: string = "bar"
  println(arg)
}

This will print to console:

null
bar

Two issues here:

  1. It shouldn't even compile since first println should see int type and require casting to string.
  2. In first println the value should be 10.
@marad marad added bug Something isn't working core Requires changes in core compiler code labels Sep 19, 2022
@marad
Copy link
Owner Author

marad commented Sep 19, 2022

To fix that compiler would have to be structured differently. The easy way out is to simply not allow name shadowing.

One idea to explore is to detect shadowing and maybe use virtual compilation scope for the rest of the function body. No idea if this is easy or not.

@marad marad added the hacktoberfest Changes good for hacktoberfest label Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core Requires changes in core compiler code hacktoberfest Changes good for hacktoberfest
Projects
None yet
Development

No branches or pull requests

1 participant