Odin icon indicating copy to clipboard operation
Odin copied to clipboard

`using` variable struct whose member variable is the same as a parameter produces no compile error

Open tienery opened this issue 3 years ago • 1 comments

Context

Currently, if you use the following code:

package main

import "core:fmt"

Foo :: struct {
    A : int,
}

Something :: struct {
    A : int,
}

main :: proc () {
    execute(20);
}

execute :: proc (A : int) {
    something := Something{};
    using something;

    A = A;
    fmt.println(something.A);
}

Does not produce a compile error, instead, runs fine and generates the image found under section below.

  • Operating System & Odin Version: Windows 10 Pro, odin version dev-2022-01-nightly:65434911
  • Please paste odin report output:

Odin: dev-2022-01-nightly:65434911 OS: Windows 10 Professional (version: 21H1), build 19043.1415 CPU: 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz RAM: 32635 MiB

Expected Behavior

Apparently, shadowing parameters is legal but can lead to some unexpected behaviour when used in conjunction with a using statement for a variable holding a member variable of the same name as that parameter.

In this instance, the compiler should at least produce a warning to suggest two variables of the same name are being used in the scope and context where the using statement is being used.

Current Behavior

By compiling and debugging the above code, the following results are seen:

image

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Copy & Paste the above code into a small file
  2. Compile and debug

tienery avatar Jan 09 '22 03:01 tienery

Hello!

I am marking this issue as stale as it has not received any engagement from the community or maintainers 120 days. That does not imply that the issue has no merit! If you feel strongly about this issue

  • open a PR referencing and resolving the issue;
  • leave a comment on it and discuss ideas how you could contribute towards resolving it;
  • leave a comment and describe in detail why this issue is critical for your use case;
  • open a new issue with updated details and a plan on resolving the issue.

The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone..

github-actions[bot] avatar Jul 24 '22 22:07 github-actions[bot]