Skip to content

Remove Option.FromBoolean and fix its calls on the compile error too - #1039

Open
FreeApophis wants to merge 1 commit into
drop-eol-frameworksfrom
remove-option-from-boolean
Open

FreeApophis wants to merge 1 commit into
drop-eol-frameworksfrom
remove-option-from-boolean

Conversation

@FreeApophis

Copy link
Copy Markdown
Member

Closes #901. Stacked on #1037 (base drop-eol-frameworks), because that PR deletes the PublicAPI files of the dropped frameworks which this one would otherwise have to touch as well. Retarget to main once #1037 is merged.

  • Option.FromBoolean (all three overloads) and Funcky.Test/Monads/Option.FromBoolean.cs are removed; every remaining TFM's PublicAPI.Unshipped.txt gets the three *REMOVED* lines.
  • OptionSomeWhereToThenRefactoring already produces Then only (done in Add bool.Then and obsolete Option.FromBoolean #997), nothing to change.
  • The FromBoolean → Then code fix stays as the migration aid, but a fix on CS0618 alone is dead once the method is gone: a project on Funcky 4.0.0 gets CS0117 ('Option' does not contain a definition for 'FromBoolean') instead. The fix therefore handles both IDs now. For CS0117 the compiler binds no overload, so the fix reconstructs the call from the syntax and the types of the arguments:
    • a lambda, a method group or a Func<T>-typed expression is the selector overload, everything else the value overload (a delegate given as item: or with an explicit delegate type argument is the value overload and becomes value:, as before);
    • the item type comes from the explicit type argument, the argument's type, the lambda's returned expressions or the method group's return type. When it cannot be told (a lambda whose return type does not bind), the call is left alone rather than risking the flattening Then(() => option) applies;
    • SelectMany(Identity) around the call is recognized by name once the receiver is an error type;
    • named arguments, evaluation-order checks, the using insertion, the "would bind to another Then" guard and Fix-All work as for CS0618.
  • New test class OptionFromBooleanRemovedCodeFixTest mirrors the CS0618 cases against a stub without FromBoolean, plus block-bodied lambdas, method groups and a fully qualified Funcky.Monads.Option receiver.
  • Changelog entry under 4.0.0 and the Then paragraph in the option chapter updated.

Verified locally: Release build of the solution with 0 warnings, Funcky.Analyzers.Test 256/256, Funcky.Test 1648/1648 on net11.0.

🤖 Generated with Claude Code

Option.FromBoolean (all three overloads), obsolete since 3.8.0, is removed
from Funcky 4.0.0 together with its tests; the PublicAPI files record the
removal. The code fix in Funcky.Analyzers stays as the migration aid, but a
fix on the obsoletion warning alone never fires once the method is gone, so
it now also handles the compile error CS0117 a call of the removed member
reports. Without a bound overload the fix reads the overload off the
arguments: a lambda, a method group or a Func<T> is the selector overload,
everything else the value overload, and a selector whose return type cannot
be told is left alone rather than risking the flattening Then applies.

Closes #901

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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 this pull request may close these issues.

1 participant