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

arrayref out-of-range error upon first function parsing #1252

Closed
carlobaldassi opened this issue Sep 4, 2012 · 5 comments
Closed

arrayref out-of-range error upon first function parsing #1252

carlobaldassi opened this issue Sep 4, 2012 · 5 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@carlobaldassi
Copy link
Member

The version of argparse.jl in this branch displays a very weird bug: the mere existence of the function call on line 1356 (marked by an "XXX") produces the following behaviour:

julia> require("argparse.jl")

julia> import ArgParse.*

julia> p = ArgumentParser();

julia> parse_args(p, {"-h"})
in ref: arrayref: index out of range
 in parse_args at /home/carlo/Programmi/julia/extras/argparse.jl:1023
 in parse_args at /home/carlo/Programmi/julia/extras/argparse.jl:1013

The error is triggered when the function _parse_short_opt (which contains the line) is called (line 1083), but I verified that the function is never actually executed, and the offending line 1356 wouldn't be reached anyway (the if clause chooses the other branch). It seems that the error occurs at parsing time. In fact, calling it twice produces the correct result the second time:

julia> p = ArgumentParser();

julia> parse_args(p, {"-h"})
in ref: arrayref: index out of range
 in parse_args at /home/carlo/Programmi/julia/extras/argparse.jl:1023
 in parse_args at /home/carlo/Programmi/julia/extras/argparse.jl:1013

julia> parse_args(p, {"-h"})
usage: <command> [-h]

optional arguments:
  -h, --help  show this help message and exit

Commenting the function call at line 1356 removes the error.
Also, the error happens only when trying to return more than one value.

@vtjnash
Copy link
Member

vtjnash commented Sep 4, 2012

It will be helpful if re-throwing errors maintained the stack-trace. But until that can be achieved, it helps to do it manually by removing the high try/catch blocks and allowing the original error to propagate the line information:

julia> parse_args(p, {"-h"})
in ref: arrayref: index out of range
in ref at array.jl:311
in tuple_elim_pass at inference.jl:1711
in typeinf at inference.jl:1119
in typeinf_ext at inference.jl:859
in _parse_args_unhandled at /Users/jameson/Documents/no-backup/julia/extras/argparse.jl:1083
in parse_args at /Users/jameson/Documents/no-backup/julia/extras/argparse.jl:1018
in parse_args at /Users/jameson/Documents/no-backup/julia/extras/argparse.jl:1013

On Sep 4, 2012, at 3:04 PM, Carlo Baldassi wrote:

The version of argparse.jl in this branch displays a very weird bug: the mere existence of the function call on line 1356 (marked by an "XXX") produces the following behaviour:

julia> require("argparse.jl")

julia> import ArgParse.*

julia> p = ArgumentParser();

julia> parse_args(p, {"-h"})
in ref: arrayref: index out of range
in parse_args at /home/carlo/Programmi/julia/extras/argparse.jl:1023
in parse_args at /home/carlo/Programmi/julia/extras/argparse.jl:1013
The error is triggered when the function _parse_short_opt (which contains the line) is called (line 1083), but I verified that the function is never actually executed, and the offending line 1356 wouldn't be reached anyway (the if clause chooses the other branch). It seems that the error occurs at parsing time. In fact, calling it twice produces the correct result the second time:

julia> p = ArgumentParser();

julia> parse_args(p, {"-h"})
in ref: arrayref: index out of range
in parse_args at /home/carlo/Programmi/julia/extras/argparse.jl:1023
in parse_args at /home/carlo/Programmi/julia/extras/argparse.jl:1013

julia> parse_args(p, {"-h"})
usage: [-h]

optional arguments:
-h, --help show this help message and exit
Commenting the function call at line 1356 removes the error.
Also, the error happens only when trying to return more than one value.


Reply to this email directly or view it on GitHub.

@timholy
Copy link
Member

timholy commented Sep 4, 2012

Could this be a case of issue #922? I never believe the line numbers for arrayref errors; I just start commenting out blocks of code and see what changes the outcome (suboptimal, of course).

@carlobaldassi
Copy link
Member Author

Ah, I didn't think about removing the try/catch block, thanks Jameson. Tim, I don't think this is related to issue 922: what I did was in fact commenting out code and insert print statements, and as I wrote I identified 1) line 1083 as the one where the error is thrown (and which shows up in Jameson's trace) and 2) line 1356 as the one which causes the error.

@timholy
Copy link
Member

timholy commented Sep 4, 2012

Sorry for the noise, carry on!

@ghost ghost assigned JeffBezanson Sep 4, 2012
@JeffBezanson
Copy link
Member

Thanks @vtjnash. Bug in code that's not running => compiler bug :)

carlobaldassi added a commit that referenced this issue Sep 6, 2012
*) renamed objects:
   +) ArgumentParser -> ArgParseSettings
   +) import_parser -> import_settings
   +) argparser_usage -> usage_string
   +) is_mandatory -> required (field option)
*) changed parse_args signature
*) removed ArgParserAction type & singletons,
   substituted with symbols (when creating arg fields,
   strings are also recognized)
*) removed add_argument
*) added alternative means to add arg fields:
   +) add_arg_table macro: allows a cleaner
      definition
   +) add_arg_table function: pass all fields
      in the same argument list
   +) add_arg_fields: use a closure to add arg
      fields
   [some of these may go away]
*) fixed and improved argument parsing
*) improved machinery to distinguish options from
   positional arguments
   +) also added an optional 'allow_ambiguous_options'
      setting (false by default)
*) import_settings can import all settings, not just
   the arg fields
*) ignore dest_name for positional arguments
*) the exception handler is now part of the settings
*) removed ugly workaround for bug #1252, now fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants