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

"@var was already defined" runtime error on typed foreach loop variable #1360

Closed
Pieter12345 opened this issue May 3, 2023 · 1 comment
Closed
Labels
bug Things that don't work as designed

Comments

@Pieter12345
Copy link
Contributor

Code

foreach(int @a in array(1, 2)) { }

or

foreach(array(1, 2) as int @a) { }

or

foreach(array(1, 2), int @a) { }

Results in

mei 03, 2023 8:59:51 P.M. com.laytonsmith.core.Static LogDebug
SEVERE: [ERROR][runtime] @a was already defined at C:\Program Files\MethodScript\Interpreter:1.1 but is being redefined.

Expected behavior is that @a can be typed without runtime error. Do note that program flow/execution is unaffected by this 'error'.

Note that this runtime error shows once per inner foreach execution for nested foreach calls:

foreach(int @a in array(1, 2, 3)) { foreach(int @b in array(1, 2, 3)) { } }

Results in

mei 03, 2023 9:08:43 P.M. com.laytonsmith.core.Static LogDebug
SEVERE: [ERROR][runtime] @a was already defined at C:\Program Files\MethodScript\Interpreter:1.1 but is being redefined.
mei 03, 2023 9:08:43 P.M. com.laytonsmith.core.Static LogDebug
SEVERE: [ERROR][runtime] @b was already defined at C:\Program Files\MethodScript\Interpreter:1.34 but is being redefined.
mei 03, 2023 9:08:43 P.M. com.laytonsmith.core.Static LogDebug
SEVERE: [ERROR][runtime] @b was already defined at C:\Program Files\MethodScript\Interpreter:1.37 but is being redefined.
mei 03, 2023 9:08:43 P.M. com.laytonsmith.core.Static LogDebug
SEVERE: [ERROR][runtime] @b was already defined at C:\Program Files\MethodScript\Interpreter:1.37 but is being redefined.

MethodScript version: Uncertain, with strict mode and static analysis enabled. MethodScript jar was last changed on 03-04-2023.

@Pieter12345 Pieter12345 added the bug Things that don't work as designed label May 3, 2023
@PseudoKnight
Copy link
Contributor

PseudoKnight commented May 3, 2023

Seems to occur when 2 foreach functions in a row use the same typed variable name, or when using nested foreach functions with a typed variable in the inner loop. (strict mode/static analysis don't have to be on)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things that don't work as designed
Projects
None yet
Development

No branches or pull requests

2 participants