From 5cce296d7cba4378837ec89d3ff7791b4f63ec92 Mon Sep 17 00:00:00 2001 From: Brian O'Connor Date: Thu, 15 Oct 2026 15:14:08 +0100 Subject: [PATCH] test: avoid C# 14 ambiguous Contains call in UniversalRpcTests From C# 14, an array converts implicitly to ReadOnlySpan, 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. --- .../Tests/Runtime/Rpc/UniversalRpcTests.cs | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Rpc/UniversalRpcTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Rpc/UniversalRpcTests.cs index fb90660844..dee47e19c9 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Rpc/UniversalRpcTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Rpc/UniversalRpcTests.cs @@ -528,6 +528,12 @@ public void SelfRecursiveRpc() } } + internal static class ClientIdArrayExtensions + { + // Not named Contains: from C# 14, ids.Contains(id) on an array is ambiguous between span extension methods. + public static bool ContainsId(this ulong[] ids, ulong id) => Array.IndexOf(ids, id) >= 0; + } + internal class UniversalRpcTestsBase : NetcodeIntegrationTest { public static int YieldCheck = 0; @@ -1557,12 +1563,12 @@ private void SendingWithGroupOverride(SendTo defaultSendTo, ulong[] recipient, u var sendMethod = senderObject.GetType().GetMethod(sendMethodName); sendMethod.Invoke(senderObject, new object[] { (RpcParams)target }); - VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.Contains(c)).ToArray(), false); - VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray()); + VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.ContainsId(c)).ToArray(), false); + VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.ContainsId(c)).ToArray()); // Pass some time to make sure that no other client ever receives this TimeTravel(1f, 30); - VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray()); + VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.ContainsId(c)).ToArray()); } private void SendingWithGroupNotOverride(SendTo defaultSendTo, ulong[] recipient, ulong objectOwner, ulong sender, AllocationType allocationType) @@ -1600,12 +1606,12 @@ private void SendingWithGroupNotOverride(SendTo defaultSendTo, ulong[] recipient var sendMethod = senderObject.GetType().GetMethod(sendMethodName); sendMethod.Invoke(senderObject, new object[] { (RpcParams)target }); - VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray(), false); - VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray()); + VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.ContainsId(c)).ToArray(), false); + VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.ContainsId(c)).ToArray()); // Pass some time to make sure that no other client ever receives this TimeTravel(1f, 30); - VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray()); + VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.ContainsId(c)).ToArray()); } #endregion @@ -2028,12 +2034,12 @@ [Values] AllocationType allocationType var sendMethod = senderObject.GetType().GetMethod(sendMethodName); sendMethod.Invoke(senderObject, new object[] { (RpcParams)target }); - VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.Contains(c)).ToArray(), false); - VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray()); + VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => recipient.ContainsId(c)).ToArray(), false); + VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.ContainsId(c)).ToArray()); // Pass some time to make sure that no other client ever receives this TimeTravel(1f, 30); - VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray()); + VerifyNotReceived(objectOwner, s_ClientIds.Where(c => !recipient.ContainsId(c)).ToArray()); } } @@ -2105,12 +2111,12 @@ [Values] AllocationType allocationType var sendMethod = senderObject.GetType().GetMethod(sendMethodName); sendMethod.Invoke(senderObject, new object[] { (RpcParams)target }); - VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.Contains(c)).ToArray(), false); - VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray()); + VerifyRemoteReceived(objectOwner, sender, sendMethodName, s_ClientIds.Where(c => !recipient.ContainsId(c)).ToArray(), false); + VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.ContainsId(c)).ToArray()); // Pass some time to make sure that no other client ever receives this TimeTravel(1f, 30); - VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.Contains(c)).ToArray()); + VerifyNotReceived(objectOwner, s_ClientIds.Where(c => recipient.ContainsId(c)).ToArray()); } }