Skip to content

Fix for issue #517 - #518

Merged
dsyme merged 4 commits into
fsprojects:masterfrom
rspeele:generative-tp-il-fix
May 22, 2026
Merged

dsyme merged 4 commits into
fsprojects:masterfrom
rspeele:generative-tp-il-fix

Conversation

@rspeele

@rspeele rspeele commented May 17, 2026

Copy link
Copy Markdown
Contributor

This fixes two minor codegen bugs for generative type providers, as described in issue #517 .

The 4 commits in this PR add a failing test for the first bug, fix the first bug to make the test pass, add a failing test for the second bug, and fix the second bug to make the test pass.

@dsyme

dsyme commented May 22, 2026

Copy link
Copy Markdown
Contributor

Looks great, thank you!

@dsyme
dsyme merged commit ceeb6bc into fsprojects:master May 22, 2026
9 checks passed
dsyme pushed a commit that referenced this pull request Jul 29, 2026
…n type (#523)

## Problem

The unit-return fix from #518 emits `I_ldnull` before `I_ret` whenever
the method's return type is unit-like:

```fsharp
let retUnit = retType = ILType.Void || retType.QualifiedName = (transType (convTypeToTgt typeof<unit>)).QualifiedName
...
if retUnit then ilg.Emit(I_ldnull)
```

The check also matches `ILType.Void`, so a `ProvidedMethod` declared
with `returnType = typeof<System.Void>` (which `transType` maps to
`ILType.Void`) gets a stray null pushed onto the stack of a
void-returning method. That is invalid IL — the stack must be empty at
`ret` in a void method — and the JIT throws `InvalidProgramException`
the first time the method is invoked:

```
System.InvalidProgramException : Common Language Runtime detected an invalid program.
   at VoidReturn.Provided.Container.Widget.DoNothing()
```

(The equivalent lambda path in `CodeGenerator.emitLambda` already gets
this right: it emits `I_ldnull` only for the FSharp.Core `Unit` return
type, not for void.)

## Fix

Split the check: `retVoid` keeps the empty-stack behavior with no
`ldnull`; only a genuine FSharp.Core `Unit` return pushes the boxed unit
value `null`.

## Testing

* New generative regression test declaring a `System.Void`-returning
method and invoking it from the loaded assembly — fails with
`InvalidProgramException` before the fix, passes after.
* Full suite green: 161/161 (including the try-finally unit-return test
added in #518).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants