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

Ambiguous use of 'init(name:parsing:help:completion:transform:)' when transform throws #618

Closed
2 tasks done
Coeur opened this issue Feb 29, 2024 · 0 comments · Fixed by #619
Closed
2 tasks done

Comments

@Coeur
Copy link
Contributor

Coeur commented Feb 29, 2024

Ambiguous use of 'init(name:parsing:help:completion:transform:)' when transform throws.

This is a regression introduced with #477 (swift-argument-parser 1.2.0).

ArgumentParser version: main branch
Swift version: swiftlang-5.11

Checklist

  • If possible, I've reproduced the issue using the main branch of this package
  • I've searched for existing GitHub issues

Steps to Reproduce

public struct MyError: Error {}

struct MyCommand: ParsableCommand {
	@Option(transform: {
		guard let url = URL(string: $0) else {
			throw MyError()
		}
		return url
	})
	var test: URL?
}

Expected behavior

No errors.

Actual behavior

Ambiguous use of 'init(name:parsing:help:completion:transform:)'

Workarounds:

  • Replacing var test: URL? with var test: URL? = nil
  • Or making the transform non-throwing
natecook1000 added a commit that referenced this issue Feb 29, 2024
Due to the restructuring in #477, there was ambiguity between the
unconstrained `@Option` initializer that uses a transform (but no
initial value) and the one that is constrained to the property being
optional. This marks the unconstrained version as disfavored, which
allows overload resolution to select the optional version when
appropriate.

Fixes #618.
natecook1000 added a commit that referenced this issue Mar 5, 2024
Due to the restructuring in #477, there was ambiguity between the
unconstrained `@Option` initializer that uses a transform (but no
initial value) and the one that is constrained to the property being
optional. This marks the unconstrained version as disfavored, which
allows overload resolution to select the optional version when
appropriate.

Also fixes this for `@Argument` and improves documentation
consistency for `@Option`.

Fixes #618.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant