Skip to content

feat(utilities): add TryResult helpers - #112

Merged
1 commit merged into
mainfrom
dev/pin-stable-bot-automerge
May 7, 2026
Merged

feat(utilities): add TryResult helpers#112
1 commit merged into
mainfrom
dev/pin-stable-bot-automerge

Conversation

@ANcpLua

@ANcpLua ANcpLua commented May 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add TryResult, an author-side helper for compact bool TryX(out T) success and failure branches.
  • Cover one, two, and three out parameters for failure and success paths, plus non-bool sentinel return values.
  • Add focused tests for defaulting, value assignment, non-nullable value-type out parameters, and composition inside a readable try-parse method.
  • Keep the branch rebased on current origin/main; the stale workflow and npm churn commits are already upstream and no longer part of this diff.

Validation

  • git diff --check origin/main...HEAD
  • dotnet test --project tests/ANcpLua.Roslyn.Utilities.Testing.Tests/ANcpLua.Roslyn.Utilities.Testing.Tests.csproj passed: 27 total, 0 failed.
  • dotnet restore ANcpLua.Roslyn.Utilities.slnx
  • dotnet build ANcpLua.Roslyn.Utilities.slnx -c Release --no-restore -p:Version=0.0.0-local
  • dotnet pack src/ANcpLua.Roslyn.Utilities/ANcpLua.Roslyn.Utilities.csproj -c Release -o artifacts/pr-pack -p:Version=0.0.0-local --no-build
  • dotnet pack src/ANcpLua.Roslyn.Utilities.Sources/ANcpLua.Roslyn.Utilities.Sources.csproj -c Release -o artifacts/pr-pack -p:Version=0.0.0-local --no-build
  • Verified ANcpLua.Roslyn.Utilities.Sources.0.0.0-local.nupkg contains contentFiles/cs/any/ANcpLua.Roslyn.Utilities/TryResult.cs.

Known Existing Failure

  • dotnet test --solution ANcpLua.Roslyn.Utilities.slnx still fails in ANcpLua.Roslyn.Utilities.ExtensibleEnumMirror.Tests because generated output is namespace TestNs.TestNs; and hits CS8955. This reproduces on detached origin/main with dotnet test --project tests/ANcpLua.Roslyn.Utilities.ExtensibleEnumMirror.Tests/ANcpLua.Roslyn.Utilities.ExtensibleEnumMirror.Tests.csproj, so it is not introduced by this PR.

Summary by CodeRabbit

Release Notes

  • New Features
    • Added TryResult utility class with methods for simplified result handling, supporting multiple output parameters and custom return values.

Copilot AI review requested due to automatic review settings May 7, 2026 01:59
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

@coderabbitai autofix

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

A new TryResult static utility class is introduced in ANcpLua.Roslyn.Utilities with overloaded helper methods for the bool TryX(out ...) pattern. The class provides Fail overloads (returning false or a sentinel value) and Ok overloads (returning true), each supporting one to three out parameters. All methods are marked with MethodImplOptions.AggressiveInlining. Generic constraints conditionally apply allows ref struct on .NET 9+ to permit ref-struct out parameters; earlier targets omit these constraints. Comprehensive unit tests validate Fail and Ok behavior across nullable/non-nullable types and composition scenarios.

🚥 Pre-merge checks | ✅ 9
✅ Passed checks (9 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title follows conventional commits format with 'feat' prefix, module scope '(utilities)', clear subject, and is 38 characters—well under the 72-character limit with no trailing period.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
No Datetime.Now/Utcnow ✅ Passed No DateTime.Now or DateTime.UtcNow found in added/modified C# files. TryResult.cs and TryResultTests.cs are clean.
No .Result/.Wait() Blocking Async ✅ Passed No blocking async patterns (.Result, .Wait(), .GetAwaiter().GetResult()) found in TryResult.cs or TryResultTests.cs. Both files are synchronous.
No Isourcegenerator ✅ Passed No ISourceGenerator implementations detected in added/modified C# files. TryResult.cs is a source-only helper class; no source generator interfaces present.
No Null-Forgiving Operator Without Justification ✅ Passed Scanned TryResult.cs and TryResultTests.cs for null-forgiving operator (!). Found only logical NOT operators and XML comment examples; no postfix null-forgiving operators present.
Sources Public Types Must Be Internal ✅ Passed No C# files in src/ANcpLua.Roslyn.Utilities.Sources/. TryResult is in the main utilities library. Transform script enforces internal visibility for the source package.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Autofix skipped. No unresolved CodeRabbit review comments with fix instructions found.

@ghost
ghost enabled auto-merge (squash) May 7, 2026 02:00
Add author-side TryResult helpers that initialize out parameters while returning the surrounding TryX result value.

Cover bool failure and success paths for one, two, and three out parameters, plus non-bool sentinel failure returns. Add focused tests for defaulting, value assignment, non-nullable value-type out parameters, and composition inside a try-parse method.
@ANcpLua
ANcpLua force-pushed the dev/pin-stable-bot-automerge branch from 6c7cd6a to 40b1b84 Compare May 7, 2026 02:00
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

@coderabbitai autofix

@ANcpLua ANcpLua left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review findings: no blocking issues in this PR diff.

Checked scope:

  • PR now contains only src/ANcpLua.Roslyn.Utilities/TryResult.cs and tests/ANcpLua.Roslyn.Utilities.Testing.Tests/TryResultTests.cs.
  • Removed the stale already-merged workflow/npm commits from the compare by rebasing onto current origin/main.
  • Tightened XML docs to avoid claiming guaranteed zero-overhead or identical IL.
  • Added coverage for non-nullable value-type out parameters, nullable outs, multi-out failure paths, non-bool sentinel returns, success assignment, and real try-parse composition.

Validation:

  • git diff --check origin/main...HEAD
  • focused TryResult test project passed: 27 total, 0 failed
  • Release solution build passed with 0 warnings and 0 errors
  • runtime and source-only packages packed; source package contains TryResult.cs

Known existing issue, not introduced here: full dotnet test --solution ANcpLua.Roslyn.Utilities.slnx fails in ANcpLua.Roslyn.Utilities.ExtensibleEnumMirror.Tests with generated namespace TestNs.TestNs; / CS8955, and the same failure reproduces on detached origin/main.

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Autofix skipped. No unresolved CodeRabbit review comments with fix instructions found.

@ghost
ghost merged commit 635fcd4 into main May 7, 2026
16 of 17 checks passed
@ghost
ghost deleted the dev/pin-stable-bot-automerge branch May 7, 2026 02:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c7cd6ac5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/// <param name="result">When this method returns, contains <c>default(T)</c>.</param>
/// <returns><c>false</c>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Fail<T>(out T? result)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use non-nullable out parameter in Fail helpers

The Fail API currently takes out T?, which makes common try-pattern signatures noisy or warning-prone in nullable-enabled projects: calling TryResult.Fail(out result) from methods that expose out string result (or generic out T result) produces nullability-mismatch diagnostics and forces callers to either relax their public signature to nullable or suppress warnings. This undercuts the intended one-liner helper for standard [MaybeNullWhen(false)] out T try methods, especially when warnings are treated as errors.

Useful? React with 👍 / 👎.

This pull request was closed.
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