-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
Typed arguments to MAIN interact poorly #3029
Comments
This appears to overlap with issues raised in #2794. |
Conjecture, based on a reading of the rakudo source (core/Main.pm6 in particular), but not tested in practice: The basic flow of RUN-MAIN (ignoring all sorts of side issues) is:
Then the candidate is run or a usage message displayed. What appears to be happening here, with a single argument for the array, is...
The final step will succeed if the scalar variable b has no type associated with it, although it will contain an array rather than the expected value. If the scalar variable has an associated type then the final step will fail, because the type of b (array) will fail to match the specified type ("Bool" in the example above). Note that if no arguments for the array variable are specified the first step will find a valid candidate and the problem will not occur. If multiple arguments for the array variable are specified then the first capture will contain an array and the problem does not occur. Fixing this will be interesting, but is way above my pay grade. |
To confirm: Consider a script similar to that above which does not contain the typed argument, but prints the variable contents:
When run with similar arguments as before...
Note the incorrect output for the "./testcli --a=c --b" case. |
Quite frankly, if you want typed arguments or array arguments in |
Problem
When MAIN has both typed named arguments and named array arguments the argument parsing can fail, producing a usage message rather than running the routine.
For example, the script
when run, produces the following...
Expected behaviour
It is expected that each case would produce "ran".
Analysis
It appears that when there is exactly one named parameter corresponding to an array argument, and another named argument which is restricted in type are both specified, then a usage message is produced rather than running the code.
This failure is also evident if you replace "Bool" with "Int".
A workaround is to remove the type restriction, in which case the code runs as expected.
[Update: The code does not run as expected in this case; the scalar variable may actually be a single-element array. See comments below.]
Environment
The above examples were run on OpenSuse Leap15 and Tumbleweed systems with the following Rakudo version:
The behaviour is the same (with a differently worded usage message) on the following rakudo versions:
The text was updated successfully, but these errors were encountered: