Commit 939a4c8
[Repo Assist] Fix generative delegate type support; implement GetInterface on ProvidedTypeDefinition (#479)
🤖 *This is an automated PR from Repo Assist, an AI assistant for this
repository.*
## Summary
Two related fixes for correctness gaps in the SDK.
---
### Bug fix: Generative delegate types were unsupported (Task 3)
Attempting to create a generative `ProvidedTypeDefinition` that extends
`System.MulticastDelegate` would previously fail at assembly-writing
time with:
> *"The provided method is not marked as an abstract method; therefore,
it should define an implementation."*
The root cause: .NET delegate types are special. Their `.ctor(object,
nativeint)` and `Invoke`/`BeginInvoke`/`EndInvoke` methods must carry
**`MethodImplAttributes.Runtime | MethodImplAttributes.Managed`** — the
CLR synthesises their bodies at JIT time, and no IL body is ever written
in the binary. The old assembly writer had no path for this case.
**Changes in `ProvidedTypes.fs`:**
- Add `ILMethodBuilder.SetImplementationFlags` to expose impl-attribute
control
- In assembly writer **phase 2**, detect delegate types
(`BaseType.FullName = "System.MulticastDelegate"`) and set
`Runtime|Managed` impl flags on all their constructors and methods
- In assembly writer **phase 3**, skip IL body emission for delegate
type constructors and methods (the CLR synthesises them)
Example usage that now works:
````fsharp
let myHandler = ProvidedTypeDefinition("MyHandler", Some typeof(System.MulticastDelegate), isErased = false)
myHandler.AddMember(
ProvidedConstructor(
[ ProvidedParameter("object", typeof(obj))
ProvidedParameter("method", typeof(nativeint)) ],
invokeCode = fun _ -> <@@ () @@>)) // invokeCode is ignored for delegate types
myHandler.AddMember(
ProvidedMethod("Invoke",
[ ProvidedParameter("sender", typeof(obj))
ProvidedParameter("e", typeof(EventArgs)) ],
typeof(Void)))
```
---
### Coding improvement: `GetInterface` now works instead of throwing
(Task 5)
`ProvidedTypeDefinition.GetInterface(name, ignoreCase)` and
`TargetTypeDefinition.GetInterface(name, ignoreCase)` previously threw
`NotSupportedException`. They now search through `GetInterfaces()`,
matching on `Name` (short name) or `FullName` (dotted name), consistent
with how `TypeDelegator` implements this in .NET.
---
### Tests
Added `tests/GenerativeDelegateTests.fs` with **5 new tests**:
| Test | What it verifies |
|------|-----------------|
| `Generative delegate type is present in generated assembly` | Type
exists with `MulticastDelegate` as base |
| `Generative delegate type has correct constructor` | `.ctor(object,
nativeint)` present with correct param types |
| `Generative delegate Invoke method has correct signature` |
`Invoke(object, EventArgs): void` |
| `Generative delegate with value return type has correct Invoke
signature` | `Invoke(int, int): int` |
| `Multiple delegate types can coexist in one container` | Both delegate
types present; both have `MulticastDelegate` base |
## Test Status
All **122 tests pass** (117 pre-existing + 5 new), `net8.0`.
```
Passed! - Failed: 0, Passed: 122, Skipped: 0, Total: 122
````
> Generated by [Repo
Assist](https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/23273901481)
·
[◷](https://github.com/search?q=repo%3Afsprojects%2FFSharp.TypeProviders.SDK+%22gh-aw-workflow-id%3A+repo-assist%22&type=pullrequests)
>
> To install this [agentic
workflow](https://github.com/githubnext/agentics/tree/346204513ecfa08b81566450d7d599556807389f/workflows/repo-assist.md),
run
> ```
> gh aw add
githubnext/agentics@3462045
> ```
<!-- gh-aw-agentic-workflow: Repo Assist, engine: copilot, id:
23273901481, workflow_id: repo-assist, run:
https://github.com/fsprojects/FSharp.TypeProviders.SDK/actions/runs/23273901481
-->
<!-- gh-aw-workflow-id: repo-assist -->
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent d2baca0 commit 939a4c8
3 files changed
Lines changed: 163 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1657 | 1657 | | |
1658 | 1658 | | |
1659 | 1659 | | |
1660 | | - | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
1661 | 1667 | | |
1662 | | - | |
| 1668 | + | |
1663 | 1669 | | |
1664 | 1670 | | |
1665 | 1671 | | |
| |||
8141 | 8147 | | |
8142 | 8148 | | |
8143 | 8149 | | |
8144 | | - | |
| 8150 | + | |
| 8151 | + | |
| 8152 | + | |
| 8153 | + | |
| 8154 | + | |
| 8155 | + | |
| 8156 | + | |
8145 | 8157 | | |
8146 | 8158 | | |
8147 | 8159 | | |
| |||
13964 | 13976 | | |
13965 | 13977 | | |
13966 | 13978 | | |
| 13979 | + | |
13967 | 13980 | | |
13968 | 13981 | | |
13969 | 13982 | | |
| |||
15760 | 15773 | | |
15761 | 15774 | | |
15762 | 15775 | | |
| 15776 | + | |
15763 | 15777 | | |
15764 | 15778 | | |
15765 | 15779 | | |
| |||
15772 | 15786 | | |
15773 | 15787 | | |
15774 | 15788 | | |
| 15789 | + | |
| 15790 | + | |
| 15791 | + | |
15775 | 15792 | | |
15776 | 15793 | | |
15777 | 15794 | | |
| |||
15819 | 15836 | | |
15820 | 15837 | | |
15821 | 15838 | | |
| 15839 | + | |
| 15840 | + | |
| 15841 | + | |
15822 | 15842 | | |
15823 | 15843 | | |
15824 | 15844 | | |
| |||
15834 | 15854 | | |
15835 | 15855 | | |
15836 | 15856 | | |
| 15857 | + | |
| 15858 | + | |
| 15859 | + | |
| 15860 | + | |
15837 | 15861 | | |
15838 | 15862 | | |
15839 | 15863 | | |
| |||
15859 | 15883 | | |
15860 | 15884 | | |
15861 | 15885 | | |
| 15886 | + | |
| 15887 | + | |
| 15888 | + | |
15862 | 15889 | | |
15863 | 15890 | | |
15864 | 15891 | | |
| |||
15925 | 15952 | | |
15926 | 15953 | | |
15927 | 15954 | | |
| 15955 | + | |
| 15956 | + | |
| 15957 | + | |
| 15958 | + | |
15928 | 15959 | | |
15929 | 15960 | | |
15930 | 15961 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
0 commit comments