Skip to content

[Repo Assist] Add isStruct convenience parameter to ProvidedTypeDefinition#464

Draft
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/improve-isstruct-convenience-parameter-ff3274e0798bf161
Draft

[Repo Assist] Add isStruct convenience parameter to ProvidedTypeDefinition#464
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/improve-isstruct-convenience-parameter-ff3274e0798bf161

Conversation

@github-actions
Copy link
Contributor

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

Adds an optional ?isStruct: bool parameter to both public constructors of ProvidedTypeDefinition. This is a Task 10 improvement that makes generating struct value types more discoverable and convenient.

Motivation

Creating a generative struct type provider currently requires knowing to set baseType = Some typeof(System.ValueType) explicitly:

// Before: easy to forget the right base type
let t = ProvidedTypeDefinition("Point", Some typeof(System.ValueType), isErased = false)

With this change, users can use a named parameter that mirrors the existing isInterface, isAbstract, isSealed pattern:

// After: explicit and self-documenting
let t = ProvidedTypeDefinition("Point", None, isStruct = true, isErased = false)
```

The traditional approach still works unchanged (full backward compatibility).

## Changes

| File | Change |
|------|--------|
| `src/ProvidedTypes.fs` | Add `isStruct` to `defaultAttributes`; add `?isStruct: bool` to both public constructors |
| `src/ProvidedTypes.fsi` | Update constructor signatures to expose `?isStruct: bool` |
| `tests/GenerativeStructProvisionTests.fs` | 4 new tests: `IsValueType`, `IsSealed`, `SequentialLayout`, traditional-approach |
| `tests/FSharp.TypeProviders.SDK.Tests.fsproj` | Include new test file |

## Behaviour when `isStruct = true`

1. `TypeAttributes.SequentialLayout` is added to the type attributes (matches what the F# and C# compilers emit for struct types by default)
2. The base type is set to `Some typeof(System.ValueType)` when `None` is passed this is what drives `IsValueType` detection, the IL type classification, and the assembly writer's `SetParent` call

## Test Status

All 108 tests pass (104 existing + 4 new):

```
Passed!  - Failed: 0, Passed: 108, Skipped: 0, Total: 108, Duration: 5 s

Generated by Repo Assist

To install this agentic workflow, run

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

Adds an optional `?isStruct: bool` parameter to both public constructors
of `ProvidedTypeDefinition`. When `isStruct = true`:

- The `TypeAttributes.SequentialLayout` flag is added automatically
- The base type defaults to `Some typeof<System.ValueType>` when `None`
  is passed (i.e., no explicit base type given)

This makes it easy to generate struct value types without needing to
remember to set the base type explicitly:

    ProvidedTypeDefinition("Point", None, isStruct = true, isErased = false)

The traditional approach still works unchanged:

    ProvidedTypeDefinition("Point", Some typeof<System.ValueType>, isErased = false)

Changes:
- ProvidedTypes.fs: add isStruct to defaultAttributes, both public ctors
- ProvidedTypes.fsi: update constructor signatures
- tests/GenerativeStructProvisionTests.fs: 4 new tests covering
  IsValueType, IsSealed, SequentialLayout, and the traditional approach
- FSharp.TypeProviders.SDK.Tests.fsproj: include new test file

All 108 tests pass (104 existing + 4 new).

Co-authored-by: Copilot <[email protected]>
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.

0 participants