Skip to content

[Repo Assist] Fix GetNestedType on generic provided type symbols (issue #336)#458

Merged
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-336-get-nested-type-on-generic-provided-type-9eab4db96e603193
Feb 26, 2026
Merged

[Repo Assist] Fix GetNestedType on generic provided type symbols (issue #336)#458
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-336-get-nested-type-on-generic-provided-type-9eab4db96e603193

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant. Fixes #336.

Problem

FSharpType.GetUnionCases (and any code that calls GetNestedType) would throw a NotSupportedException when called on a type created with ProvidedTypeBuilder.MakeGenericType where at least one type argument is a provided type. For example:

let typ = ProvidedTypeDefinition("Blah", Some typeof(obj))
let optionTyp = ProvidedTypeBuilder.MakeGenericType(typedefof<_ option>, [ typ ])
// ↑ This is TypeSymbol(OtherGeneric(typedefof<_ option>), [typ])

let cases = FSharp.Reflection.FSharpType.GetUnionCases(optionTyp)
// ↑ Throws: "The operation 'GetNestedType' on item 'FSharpOption`1' should not be called
//   on provided type, member or parameter of type 'TypeSymbol'"

Root cause

ProvidedTypeBuilder.MakeGenericType(typedefof<_ option>, [someProvidedType]) produces a TypeSymbol with TypeSymbolKind.OtherGeneric. Its GetNestedType override unconditionally called notRequired, even though the underlying generic type definition (FSharpOption(T)) is a real .NET type that supports GetNestedType.

Separately, ProvidedTypeSymbol (used when the generic type definition itself is a provided type) had the same gap.

Fix

Delegate GetNestedType to the underlying generic type definition for both cases — exactly the same pattern already used by GetNestedTypes at the same sites.

// TypeSymbol (OtherGeneric path)
override this.GetNestedType(name, bindingFlags) =
    match kind with
    | TypeSymbolKind.OtherGeneric gtd -> gtd.GetNestedType(name, bindingFlags)
    | _ -> notRequired this "GetNestedType" this.Name

// ProvidedTypeSymbol (Generic path)
override this.GetNestedType(name, bindingFlags) =
    match kind with
    | ProvidedTypeSymbolKind.Generic gty -> gty.GetNestedType(name, bindingFlags)
    | _ -> notRequired this "GetNestedType" this.FullName

Test status

✅ New regression test GetUnionCases works on option of provided type passes.
✅ All 103 existing tests pass, 1 pre-existing skip unchanged (dotnet test tests/ -c Release).

Generated by Repo Assist for issue #336

Generated by Repo Assist

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@69c1ee19e39e6aaba35519aafefb5cbf314de323

…ed types

When a type provider uses ProvidedTypeBuilder.MakeGenericType to create
e.g. option<SomeProvidedType>, the resulting TypeSymbol (OtherGeneric)
did not implement GetNestedType, causing FSharpType.GetUnionCases to
throw NotSupportedException.

Fix: delegate GetNestedType to the underlying generic type definition
in both TypeSymbol (OtherGeneric) and ProvidedTypeSymbol (Generic) cases,
matching the existing pattern used by GetNestedTypes at those sites.

Adds a regression test covering GetUnionCases on option<ProvidedType>.

Fixes #336

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review February 26, 2026 13:18
@dsyme dsyme merged commit e9e0f0c into master Feb 26, 2026
2 checks passed
dsyme pushed a commit that referenced this pull request Mar 7, 2026
🤖 *This PR was created by Repo Assist, an automated AI assistant.*

Prepares the RELEASE_NOTES.md for version **8.3.0** — a minor release
capturing significant improvements merged since 8.2.0 (February 24).

## Changes since 8.2.0

| Type | PR | Description |
|------|----|-------------|
| 🐛 Bug fix | #432 | Fix custom attributes on nested erased types |
| 🐛 Bug fix | #458 | Fix `GetNestedType` on
`TypeSymbol`/`ProvidedTypeSymbol` for generic provided types |
| 🐛 Bug fix | #459 | Fix mutable variable captures in
`QuotationSimplifier` — promote to ref cells |
| ⚡ Performance | #443 | Memoize `transType` in `AssemblyCompiler` to
reduce redundant type translation |
| ⚡ Performance | #457 | Cache `transTypeRef` and `transMethRef` in
assembly compiler |
| ✨ Feature | #428 | New warning when all static parameters in a type
provider are optional |
| 📚 Docs | #455 | Documentation guide overhaul |
| 🧪 Tests | #442 | Add coverage tests and Coverage build target |
| 🔧 Toolchain | #431 | Update to .NET 8 SDK and toolchain |

This is a minor version bump (8.2.0 → 8.3.0) due to the new feature
(#428) and significant improvements. If preferred, a patch release
(8.2.1) is also reasonable given the emphasis on bug fixes.

## Test Status

This PR only modifies RELEASE_NOTES.md. The build/test status for the
underlying changes is tracked in the individual PRs listed above (all
passed CI before merging).

---

*To release: merge this PR, then tag `v8.3.0` and publish the NuGet
package via the existing build pipeline.*




> Generated by [Repo
Assist](https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/22448247879)
>
> To install this [agentic
workflow](https://github.com/githubnext/agentics/tree/afb00b92a9514fee9a14c583f059a03d05738f70/workflows/repo-assist.md),
run
> ```
> gh aw add
githubnext/agentics@afb00b9
> ```

<!-- gh-aw-agentic-workflow: Repo Assist, engine: copilot, id:
22448247879, workflow_id: repo-assist, run:
https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/22448247879
-->

<!-- gh-aw-workflow-id: repo-assist -->

---------

Co-authored-by: Repo Assist <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GetUnionCases fails on an option of provided type

1 participant