This problem seems to be related to the „forward references“ feature of JShell: When a method or type declaration refers to a still undefined variable or method, JShell checks only for syntactical correctness and delays the compilation of the method resp. type. In interactive mode it prints a helpful message like „method x refers to undefined method y and can’t be invoked until method y is defined“. But while a startup script runs, that message is not printed and in many cases the script executes nothing, which is very confusing. I have not found a way to enable the printing of that message.
Hypercritical persons might say that this bug/feature renders JShell useless for „real“ scripting applications, and I tend to agree.
I propose that the „forward references“ feature be disabled during the execution of scripts. In order to make forward references still possible, the entire script should be considered ONE big snippet. That would also eliminate the problem with line-numbers-per-snippet which makes no sense at all with code parsed from scripts.