Skip to content

Commit 99f4812

Browse files
[repo-assist] tests: cover ProvidedTypeBuilder.MakeTupleType isStruct overload and large-tuple encoding (#541)
🤖 *This is an automated pull request from Repo Assist, an AI assistant. Please review carefully before merging.* ## Summary - Tests: Add 2 regression tests for `ProvidedTypeBuilder.MakeTupleType`: - The `isStruct: bool` overload, verifying it produces `System.ValueTuple<...>`-based types (vs. `System.Tuple<...>` for `isStruct = false`), and that the single-argument overload defaults to `isStruct = false`. - The recursive "rest" tuple encoding used for tuples with more than 8 elements (e.g. a 9-element tuple becomes `Tuple<T1..T7, Tuple<T8,T9>>`), for both reference and struct tuples. ## Rationale `ProvidedTypeBuilder.MakeTupleType` is a public SDK API used by type provider authors to build tuple types (including via F# quotation-based code generation, where struct tuples and large tuples both arise naturally). Before this change, only the small (2-element), non-struct case was exercised by the test suite — the `isStruct = true` branch and the `>8`-element recursive-encoding branch (`tupleNames.[n - 1 + (if isStruct then 9 else 0)]` and the recursive `mkTupleType` call in `src/ProvidedTypes.fs`) had no direct test coverage. ## Trade-offs - Test-only change; no production code modified. ## Test Status - `dotnet test tests/FSharp.TypeProviders.SDK.Tests.fsproj -c Release`: **Passed** — 167/167 tests, 0 failures, 0 skipped (net8.0). This includes the 2 new tests (total was 165 before this change). - `dotnet build src/FSharp.TypeProviders.SDK.fsproj -c Release`: **Passed** — 0 warnings, 0 errors (netstandard2.0 + net8.0) - `./build.sh RunTests` (FAKE) was not used because FAKE's `RunTests` target requires resolving the SDK's runtime pack list over the network, which is blocked by the sandbox proxy (403) in this environment. `dotnet test` was used directly as a reliable substitute and passed cleanly. > [!WARNING] > <details> > <summary>Firewall blocked 1 domain</summary> > > The following domain was blocked by the firewall during workflow execution: > > - `dotnetcli.azureedge.net` > > To allow these domains, add them to the `network.allowed` list in your workflow frontmatter: > > ```yaml > network: > allowed: > - defaults > - "dotnetcli.azureedge.net" > ``` > > See [Network Configuration](https://github.github.com/gh-aw/reference/network/) for more information. > > </details> > Generated by 🌈 Repo Assist, see [workflow run](https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/35957718071). [Learn more](https://github.com/githubnext/agentics/blob/main/docs/repo-assist.md). > <sub>Comment <em>/repo-assist</em> to run again</sub> > <details> <summary><sub>Add this agentic workflow to your repo</sub></summary> To install this agentic workflow, run ``` gh aw add githubnext/agentics@4bc8419 ``` </details> <!-- gh-aw-agentic-workflow: Repo Assist, engine: copilot, model: auto, id: 35957718071, workflow_id: repo-assist, run: https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/35957718071 --> <!-- gh-aw-workflow-id: repo-assist --> <!-- gh-aw-workflow-call-id: fsprojects/FSharp.TypeProviders.SDK/repo-assist --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d208217 commit 99f4812

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎tests/BasicErasedProvisionTests.fs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,40 @@ let ``test ProvidedStaticParameter properties``() =
639639
Assert.Equal("hello", p2.RawDefaultValue :?> string)
640640
Assert.True(p2.Attributes.HasFlag(ParameterAttributes.Optional), "parameter with default should be Optional")
641641

642+
// Tests for ProvidedTypeBuilder.MakeTupleType(types, isStruct) -- the isStruct=true overload
643+
// produces System.ValueTuple-based types rather than System.Tuple-based reference types.
644+
[<Fact>]
645+
let ``test ProvidedTypeBuilder MakeTupleType isStruct true produces ValueTuple``() =
646+
let refTuple = ProvidedTypeBuilder.MakeTupleType([ typeof<int>; typeof<string> ], false)
647+
Assert.Equal(typedefof<System.Tuple<int, string>>, refTuple.GetGenericTypeDefinition())
648+
Assert.False(refTuple.IsValueType, "reference tuple should not be a value type")
649+
650+
let structTuple = ProvidedTypeBuilder.MakeTupleType([ typeof<int>; typeof<string> ], true)
651+
Assert.Equal(typedefof<System.ValueTuple<int, string>>, structTuple.GetGenericTypeDefinition())
652+
Assert.True(structTuple.IsValueType, "struct tuple should be a value type")
653+
654+
// The single-argument overload defaults to isStruct = false
655+
let defaultTuple = ProvidedTypeBuilder.MakeTupleType([ typeof<int>; typeof<string> ])
656+
Assert.Equal(refTuple, defaultTuple)
657+
658+
// Tests for ProvidedTypeBuilder.MakeTupleType with more than 8 elements, which exercises the
659+
// recursive "rest" tuple encoding used by System.Tuple/System.ValueTuple for large tuples.
660+
[<Fact>]
661+
let ``test ProvidedTypeBuilder MakeTupleType large tuple uses TRest encoding``() =
662+
let types = [ for i in 1 .. 9 -> typeof<int> ]
663+
let bigTuple = ProvidedTypeBuilder.MakeTupleType(types)
664+
665+
// A 9-element reference tuple is encoded as Tuple<int,...,int, Tuple<int,int>> (7 + a nested 2-tuple "rest")
666+
Assert.Equal(typedefof<System.Tuple<int, int, int, int, int, int, int, System.Tuple<int, int>>>, bigTuple.GetGenericTypeDefinition())
667+
let genericArgs = bigTuple.GetGenericArguments()
668+
Assert.Equal(8, genericArgs.Length)
669+
let restTy = genericArgs.[7]
670+
Assert.Equal(typedefof<System.Tuple<int, int>>, restTy.GetGenericTypeDefinition())
671+
672+
// Same large-tuple recursive encoding also applies to struct tuples
673+
let bigStructTuple = ProvidedTypeBuilder.MakeTupleType(types, true)
674+
Assert.Equal(typedefof<System.ValueTuple<int, int, int, int, int, int, int, System.ValueTuple<int, int>>>, bigStructTuple.GetGenericTypeDefinition())
675+
642676
// Tests for TypeProviderForNamespaces.AddNamespace, Namespaces, and Invalidate
643677
[<Fact>]
644678
let ``test TypeProviderForNamespaces AddNamespace and Namespaces``() =

0 commit comments

Comments
 (0)