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

flag.FlagParser bug with certain combination of flags #22155

Closed
larpon opened this issue Sep 3, 2024 · 0 comments · Fixed by #22160
Closed

flag.FlagParser bug with certain combination of flags #22155

larpon opened this issue Sep 3, 2024 · 0 comments · Fixed by #22160
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@larpon
Copy link
Contributor

larpon commented Sep 3, 2024

Describe the bug

There's a bug somewhere in flag.FlagParser that looks like it eats h characters from other input flags/arguments.

Reproduction Steps

v run bug.v:

bug.v:

module main

import flag

pub struct Options {
pub:
	verbosity  int
	dump_usage bool
pub mut:
	additional_args []string
	archs           []string
	v_flags         []string
	api_level       string
}

fn main() {
	args := ['/my/app', '-v', '3', '-f', '-d sdl_memory_no_gc', '-f', '-d shy_use_wren', '--api',
		'21', '--archs', 'arm64-v8a', '/path/to/input.v']

	mut fp := flag.new_flag_parser(args)
	fp.application('bug')
	fp.version('0.2.0')
	fp.description('bugged')
	fp.arguments_description('not important')

	fp.skip_executable()

	mut opt := Options{
		v_flags:    fp.string_multi('flag', `f`, 'Additional flags for the V compiler')
		archs:      fp.string('archs', 0, 'arm64-v8a,armeabi-v7a,x86,x86_64', 'Comma separated string with any of archs').split(',')
		dump_usage: fp.bool('help', `h`, false, 'Show this help message and exit')
		verbosity:  fp.int_opt('verbosity', `v`, 'Verbosity level 1-3') or { 0 }
		api_level:  fp.string('api', 0, '21', 'Android API level to use (--list-apis)')
	}

	opt.additional_args = fp.finalize() or { panic(err) }

	assert opt.v_flags[0] == '-d sdl_memory_no_gc'
	assert opt.v_flags[1] == '-d shy_use_wren' // looks like the builtin support for `-h` eats the "h" in this flag
	assert opt.dump_usage == false
}

Expected Behavior

No assert failures

Current Behavior

./bug.v:41: FAIL: fn main.main: assert opt.v_flags[1] == '-d shy_use_wren'
   left value: opt.v_flags[1] = -d sy_use_wren
  right value: '-d shy_use_wren' = -d shy_use_wren
V panic: Assertion failed...
v hash: 0a61b4a
/dev/shm/v_1000/bug.01J6VQ1CTXWF36ZDQWPBJYG42P.tmp.c:7505: at _v_panic: Backtrace
/dev/shm/v_1000/bug.01J6VQ1CTXWF36ZDQWPBJYG42P.tmp.c:15316: by main__main
/dev/shm/v_1000/bug.01J6VQ1CTXWF36ZDQWPBJYG42P.tmp.c:15375: by main

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7 0a61b4a

Environment details (OS name and version, etc.)

Linux, EndeavourOS (Arch-based)

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@larpon larpon added the Bug This tag is applied to issues which reports bugs. label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant