EngineHub / CommandHelper

Rapid scripting and command aliases for Minecraft owners
https://methodscript.com
Other
119 stars 71 forks source link

Using unexisting functions in `foreach(... in ...) {}` syntax results in unexpected additional compile errors #1356

Closed Pieter12345 closed 1 year ago

Pieter12345 commented 1 year ago

Problem

This program which uses unexisting function bla() foreach(@a in bla()) {} results in the following compile errors (with strict mode and static analysis enabled):

COMPILE ERROR: Unexpected statement; foreach not allowed in this context.
        at :Unknown Source:0.0

COMPILE ERROR: Arguments (auto, void) do not match required (Iterable, [any], any, any).
        at :Interpreter:1.1

COMPILE ERROR: Variable cannot be resolved (missing variable scope, this is an internal error that should never happen): @a
        at :Interpreter:1.9

COMPILE ERROR: Unexpected keyword: in
        at :Interpreter:1.12

COMPILE ERROR: The function "bla" does not exist in the Java Interpreter
        at :Interpreter:1.15

Expected behavior

The issue is that we get the additional compile errors from foreach failing to be parsed, whereas my expectation would be that the unexisting function would be handled as a regular function with the auto return type. This would result in the following single compile error:

COMPILE ERROR: The function "bla" does not exist in the Java Interpreter
        at :Interpreter:1.15

Possible causes

Without having inspected the code, the problem could be that:

Version

CommandHelper build 320 cmdline interpreter with strict mode and static analysis enabled.