[wasm][R2R] Closed static delegate returning a struct with object references fails
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Description
`System.Tests.DelegateTests.ClosedStaticDelegate` fails with NullReferenceException in browser CoreCLR R2R library tests. The existing test creates a closed static extension-method delegate returning a struct containing two object references.
A clean aggressively trimmed non-R2R build passes the same test, so this is an R2R execution failure rather than a missing trimmer descriptor.
### Reproduction Steps
Build browser CoreCLR libraries and packs with host crossgen2, then run:
```sh
XHARNESS_COMMAND=test-browser ./dotnet.sh build /t:Test src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj \
/p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=CoreCLR /p:Configuration=Release \
/p:PublishReadyToRun=true /p:EnableAggressiveTrimming=true \
/p:Scenario=WasmTestOnChrome /p:InstallChromeForTests=true \
'/p:WasmTestAppArgs=-method System.Tests.DelegateTests.ClosedStaticDelegate'
```
This uses the shared mobile trimming descriptors being enabled for browser in #133193, plus publishing prerequisite #133378.
### Expected behavior
The delegate returns the same two object references held in its receiver's struct field, and both `Assert.Same` checks succeed.
### Actual behavior
```text
[FAIL] System.Tests.DelegateTests.ClosedStaticDelegate
System.NullReferenceException : Object reference not set to an instance of an object.
at System.Object.GetType()
at System.Tests.DelegateTests.ClosedStaticDelegate()
```
The precise failing transition/ABI mechanism has not been isolated.
### Regression?
Unknown. This is newly exposed by the R2R library-test lane. The test passes without R2R using clean project outputs and the same aggressive trimming. It still fails after correcting the unrelated CoreLib dynamic-code trimming substitution.
### Known Workarounds
Quarantine only this test on browser R2R, preserving its interpreter and desktop coverage.
### Configuration
Browser-wasm CoreCLR Release, macOS arm64 build host, Chromium 153. Runtime native base `798449390515fa02f4b20160bedc5e34f8fbdfb9`, with publishing prerequisite #133378 at `245cb70d593f2c8f3a4e23bcc422e7da5926e15b`.
### Other information
Found during #133193. The existing regression test is in `src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DelegateTests.cs`.
> [!NOTE]
> This issue was generated by GitHub Copilot from local test results and source inspection.
Contributor guide
Research direction
Start with src/libraries/System.Runtime/tests/System.Runtime.Tests/System/DelegateTests.cs and reproduce System.Tests.DelegateTests.ClosedStaticDelegate using the browser CoreCLR R2R command in the issue. Compare the R2R failure with the passing clean non-R2R build and trace the transition or ABI involved. Done means both Assert.Same checks pass in browser R2R without quarantining the test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, wasm
- Domain
- build-system, compilers, testing-qa
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100