Skip to content

fix: a generated TryParse ends at its return, with no unreachable tail - #106

Merged
CaffeinatedCoder merged 1 commit into
release/2.3.0from
fix/tryparse-dead-code
Oct 28, 2026
Merged

CaffeinatedCoder merged 1 commit into
release/2.3.0from
fix/tryparse-dead-code

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #100

Problem

Every generated TryParse(string?, IFormatProvider?, out TSelf) over a wrapped type with a TryParse of its own, or over a string, ended in unreachable code after its return: a declaration of __inner and a try/catch (FormatException). TryParseTemplate returned from a compile-time if, which ends the run-time body, but its two meta.InsertStatement calls are compile-time code and still ran. It did nothing at run time. It was in every value object that parses, though, and it showed up in the woven code a reviewer reads and in the excerpts the READMEs now show (#92). The AspectTesting spike found it (#93).

Change

  • ValueObjectParsableAspect.Templates.cs: the three branches of TryParseTemplate form an if-else chain, so the InsertStatements run only in the last branch. That branch covers the strategies without a TryParse of their own: a type converter, a static Parse, a string constructor. Their bodies are unchanged.
  • WovenReachabilityTests (conventions): reads the probes' woven files and fails on any statement after a return or a throw of the same block, a local function excepted.

Tests

  • Before the fix the new test finds 26 unreachable statements, one per probe value object that parses. After it, none. A fixture pins what counts, and a floor checks that the woven TryParses are read at all.
  • Variants: the probes hold every parse strategy. The four final-branch bodies (ProbeInstant, ProbeLocalDate, ProbeSku, ProbeIsbn) are the same as before. The only other template calling InsertStatement, JsonConverterWriteTemplate, has no early return.
  • Full suite: 18,214 passed. No prober or oracle seed patches the template.

🤖 Generated with Claude Code

Every generated TryParse(string?, IFormatProvider?, out TSelf) over a wrapped type with a TryParse
of its own, or over a string, ended in a declaration of __inner and a try/catch (FormatException)
after its return. TryParseTemplate returned from a compile-time if, which ends the run-time body,
but the two meta.InsertStatement calls after it are compile-time code and still ran. Nothing reached
the tail and it changed no behaviour, but it was in every value object that parses, and in the code
the READMEs now show. The AspectTesting spike found it reading its expected output (#93).

The three branches are an if-else chain now, so the InsertStatements run only in the last one: the
strategies without a TryParse of their own (a type converter, a static Parse, a string
constructor), whose body is unchanged.

WovenReachabilityTests (conventions) reads the probes' woven files and fails on any statement after a
return or a throw of the same block, a local function excepted. Before the fix it found 26, one per
value object of the probes that parses; after it, none. A fixture pins what counts.

Input class: the parse strategies. The probes hold each of them (string, enum, Uri, the primitives
and dates, a span-parsable type, NodaTime through its type converter, a static Parse, a string
constructor), and the four final-branch bodies are the same as before. The other template that calls
InsertStatement, JsonConverterWriteTemplate, has no early return.

Closes #100

Defect-Class: GTS
Found-By: SF
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 2.3.0 milestone Oct 28, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working severity/low Cosmetic, message or documentation-level difference package/generators Affects CodoMetis.TypeKit.Generators area/parsing Parse, TryParse, formatting and the type converter labels Oct 28, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 584df3d into release/2.3.0 Oct 28, 2026
14 of 15 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/tryparse-dead-code branch October 28, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/parsing Parse, TryParse, formatting and the type converter bug Something isn't working package/generators Affects CodoMetis.TypeKit.Generators severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant