CommandHelper

CommandHelper

46.5k Downloads

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

Pieter12345 opened this issue ยท 0 comments

commented

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:

  • The unexisting function skips some handling in MethodScriptCompiler, as some things swallow the exception from the function lookup and continue with the next AST term.
  • The foreach keyword in combination with in doesn't parse because the unexisting function's AST term is in some different format.

Version

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