Skip to content

test: avoid C# 14 ambiguous Contains call in UniversalRpcTests - #4193

Open
BrianUnity wants to merge 2 commits into
develop-3.x.xfrom
fix/csharp14-contains-ambiguity-universalrpctests
Open

BrianUnity wants to merge 2 commits into
develop-3.x.xfrom
fix/csharp14-contains-ambiguity-universalrpctests

Conversation

@BrianUnity

@BrianUnity BrianUnity commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Purpose of this PR

UniversalRpcTests.cs does not compile with C# 14. The compiler reports error CS0121 (ambiguous call) at 12 lines like this one:

s_ClientIds.Where(c => recipient.Contains(c))

recipient is a ulong[]. C# 14 can convert an array to a ReadOnlySpan<T> automatically. Because of this, two span methods now match recipient.Contains(c):

  • System.MemoryExtensions.Contains
  • Unity.Collections.NativeArrayExtensions.Contains

The compiler cannot choose between them.

This PR adds a small extension method, ContainsId, that uses Array.IndexOf. The 12 lines now call recipient.ContainsId(c). The new name does not match the span methods, so the call is not ambiguous. The behavior does not change, and the code still compiles with older C# versions.

I searched the rest of the package for the same problem and found none.

Jira ticket

UUM-155844

Documentation

  • No documentation changes or additions were necessary.

Testing & QA (How your changes can be verified during release Playtest)

Functional Testing

Automated tests:

  • Covered by existing automated tests

With the same Array.IndexOf check, all PlayMode tests passed on .NET 10 (5378 passed, 0 failed).

Up-port

Not needed. This PR targets the newest branch.

Backports

develop-2.0.0 and develop have the same 12 lines. They need the same fix if they must compile with C# 14.

From C# 14, an array converts implicitly to ReadOnlySpan<T>, so
recipient.Contains(c) on a ulong[] matches both
MemoryExtensions.Contains and Unity.Collections'
NativeArrayExtensions.Contains, and the compiler reports CS0121.

Add a ContainsId extension method backed by Array.IndexOf and use it
at the 12 affected call sites. It compiles the same way on C# 9.
@BrianUnity BrianUnity changed the title Tests: Avoid C# 14 ambiguous Contains call in UniversalRpcTests test: Avoid C# 14 ambiguous Contains call in UniversalRpcTests Oct 15, 2026
@BrianUnity BrianUnity changed the title test: Avoid C# 14 ambiguous Contains call in UniversalRpcTests test: avoid C# 14 ambiguous Contains call in UniversalRpcTests Oct 15, 2026
@BrianUnity
BrianUnity marked this pull request as ready for review October 16, 2026 10:44
@BrianUnity
BrianUnity requested a review from a team as a code owner October 16, 2026 10:44
@u-pr

u-pr Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

⚠️ Some settings were ignored in '.pr_agent.toml (repository root)' repo settings

Check the configuration's TOML syntax, permitted settings, and size limit. See the error below.


Error message:
Ignored prohibited settings: github_app.handle_pr_actions. Permitted settings were applied.

Configuration content:
# This is the configuration for the u-pr bot
# https://github.cds.internal.unity3d.com/unity/u-pr
# For configuration of this file:
# https://developer.portal.internal.unity.com/catalog/default/component/u-pr/docs/configuration/automatic_runs/

[github_app]
handle_pr_actions = ['opened', 'ready_for_review']  # PR events that auto-run pr_commands
pr_commands       = ["/harness-review"]             # what runs on those events
reviewer_commands = ["/harness-review"]             # what runs when @u-pr is added as reviewer

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Harness Review

Ship it

The helper avoids the C# 14 overload ambiguity while preserving array membership behavior. I examined all 12 replacements, the helper’s scope, and the recipient inputs in both current and legacy tests; no actionable issues were found.

Reviewed commit 5cce296

🤖 Helpful? 👍/👎

@codecov-github-com

codecov-github-com Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

@@              Coverage Diff               @@
##           develop-3.x.x    #4193   +/-   ##
==============================================
  Coverage          76.11%   76.11%           
==============================================
  Files                159      159           
  Lines              27333    27333           
==============================================
  Hits               20805    20805           
  Misses              6528     6528           
Flag Coverage Δ
NGOv2_project_testproject_ubuntu 75.16% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
com.unity.netcode.gameobjects 76.11% <ø> (ø)

ℹ️ Need help interpreting these results?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants