rascal icon indicating copy to clipboard operation
rascal copied to clipboard

Variable in pattern match RHS marked as use of declaration in LHS

Open toinehartman opened this issue 6 months ago • 0 comments

Describe the bug

It seems that variables in the RHS of a pattern match can be resolved as a use of the declaration on the LHS of the match. This is suprising, since the LHS should only be declared after resolving the RHS.

To Reproduce

void f(int i) { // warning: "unused formal `i`"
    if (int i := i) { // RHS `i` resolves to LHS `i` instead of to formal declaration
        ;
    }
}

In this example, the i in the RHS of the pattern match resolves to the i in the LHS. Additionally, the formal parameter declaration int i is marked as unused, since the declaration int i in the LHS of the pattern match shadows it.

Expected behavior

  • First int i: formal declaration
  • Second int i: pattern var declaration
  • Third i: use of formal int i

Screenshots Image

Desktop (please complete the following information):

  • Context: at least in VS Code
  • Rascal Version: 0.41.0-RC42

toinehartman avatar May 15 '25 09:05 toinehartman