From 796f5023b1ba310c94356125d3a06b16a976df38 Mon Sep 17 00:00:00 2001 From: qflen Date: Tue, 21 Apr 2026 19:42:20 +0200 Subject: [PATCH 1/2] Improve diagnostic for @Flag Bool? without inversion: When a user declares `@Flag(...) var x: Bool?` without the required `inversion:` parameter, overload resolution falls through to the `Flag where Value == Int` initializer and the compiler reports "requires the types 'Bool?' and 'Int' be equivalent", which does not point the user at the real cause. Add an `@available(*, unavailable)` init overload on `Flag where Value == Bool?` with a message that names the missing parameter. Follows the same pattern used for the unavailable no-arg `Flag.init()` at the top of the file. Resolves #835. --- .../Parsable Properties/Flag.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/ArgumentParser/Parsable Properties/Flag.swift b/Sources/ArgumentParser/Parsable Properties/Flag.swift index 6c1106891..c4eb25262 100644 --- a/Sources/ArgumentParser/Parsable Properties/Flag.swift +++ b/Sources/ArgumentParser/Parsable Properties/Flag.swift @@ -251,6 +251,24 @@ extension Flag where Value == Bool? { exclusivity: exclusivity, help: help) } + + /// Surfaces a clearer diagnostic when a user declares a `Bool?` flag without + /// the required `inversion:` parameter. + /// + /// Without this overload, the compiler falls back to the + /// `Flag where Value == Int` initializer and reports a confusing + /// "types 'Bool?' and 'Int' be equivalent" error. + @available( + *, unavailable, + message: + "An optional 'Bool?' @Flag requires an 'inversion:' parameter, such as '.prefixedNo' or '.prefixedEnableDisable'." + ) + public init( + name: NameSpecification = .long, + help: ArgumentHelp? = nil + ) { + fatalError("unavailable") + } } extension Flag where Value == Bool { From c82827ce6411da54fb4bed06ee40b91ad60cda07 Mon Sep 17 00:00:00 2001 From: kimon Date: Wed, 22 Apr 2026 20:40:42 +0200 Subject: [PATCH 2/2] =?UTF-8?q?escape=20=C2=A0=5Fname=C2=A0=20so=20it=20re?= =?UTF-8?q?nders=20correctly=20in=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nate Cook --- Sources/ArgumentParser/Parsable Properties/Flag.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ArgumentParser/Parsable Properties/Flag.swift b/Sources/ArgumentParser/Parsable Properties/Flag.swift index c4eb25262..4a2353da8 100644 --- a/Sources/ArgumentParser/Parsable Properties/Flag.swift +++ b/Sources/ArgumentParser/Parsable Properties/Flag.swift @@ -264,7 +264,7 @@ extension Flag where Value == Bool? { "An optional 'Bool?' @Flag requires an 'inversion:' parameter, such as '.prefixedNo' or '.prefixedEnableDisable'." ) public init( - name: NameSpecification = .long, + name _name: NameSpecification = .long, help: ArgumentHelp? = nil ) { fatalError("unavailable")