Skip to content

Commit 788f319

Browse files
committed
Fix issues that only show up when the interceptor is not used
This enables a bunch of tests that were previously not running when the interceptor is suppressed. Once we run them in that context, many of them were failing. I fix those bugs here.
1 parent 84394f0 commit 788f319

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/StreamJsonRpc/Reflection/ProxyBase.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,22 +381,17 @@ private static bool ProxyImplementsCompatibleSetOfInterfaces(
381381
JsonRpcProxyOptions? options)
382382
{
383383
HashSet<Type> proxyInterfaces = [.. proxyClass.GetInterfaces()];
384-
if (!proxyInterfaces.Remove(contractInterface))
385-
{
386-
return false;
387-
}
388384

389-
foreach (Type addl in additionalContractInterfaces)
385+
// Put all the interfaces required into a set so that duplicates are removed.
386+
HashSet<Type> requiredInterfaces = [contractInterface, .. additionalContractInterfaces];
387+
foreach ((Type addl, _) in implementedOptionalInterfaces)
390388
{
391-
if (!proxyInterfaces.Remove(addl))
392-
{
393-
return false;
394-
}
389+
requiredInterfaces.Add(addl);
395390
}
396391

397-
foreach ((Type addl, _) in implementedOptionalInterfaces)
392+
foreach (Type reqd in requiredInterfaces)
398393
{
399-
if (!proxyInterfaces.Remove(addl))
394+
if (!proxyInterfaces.Remove(reqd))
400395
{
401396
return false;
402397
}
@@ -421,22 +416,35 @@ private static bool ProxyImplementsCompatibleSetOfInterfaces(
421416
continue;
422417
}
423418

419+
bool ok = false;
424420
foreach (Type addl in additionalContractInterfaces)
425421
{
426422
if (remaining.IsAssignableFrom(addl))
427423
{
424+
ok = true;
428425
continue;
429426
}
430427
}
431428

429+
if (ok)
430+
{
431+
continue;
432+
}
433+
432434
foreach ((Type addl, _) in implementedOptionalInterfaces)
433435
{
434436
if (remaining.IsAssignableFrom(addl))
435437
{
438+
ok = true;
436439
continue;
437440
}
438441
}
439442

443+
if (ok)
444+
{
445+
continue;
446+
}
447+
440448
// This is an extra, unwanted interface.
441449
return false;
442450
}

test/StreamJsonRpc.Tests/JsonRpcProxyGenerationTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,11 @@ private static void DynamicAssembliesKeyedByAssemblyLoadContext_Helper(JsonRpcPr
997997

998998
#if NO_INTERCEPTORS
999999
public class Dynamic(ITestOutputHelper logger) : JsonRpcProxyGenerationTests(logger, JsonRpcProxyOptions.ProxyImplementation.AlwaysDynamic);
1000-
#else
1000+
#endif
1001+
10011002
public class SourceGenerated(ITestOutputHelper logger) : JsonRpcProxyGenerationTests(logger, JsonRpcProxyOptions.ProxyImplementation.AlwaysSourceGenerated)
10021003
{
1004+
#if !NO_INTERCEPTORS
10031005
/// <summary>
10041006
/// The interceptor cannot fallback to dynamic proxies at runtime when the Options demands it,
10051007
/// because doing so would generate linker warnings for NativeAOT apps.
@@ -1066,9 +1068,8 @@ public async Task CheckedInProxiesFromPastGenerationsStillWork()
10661068

10671069
Assert.Equal(0, failures);
10681070
}
1069-
}
1070-
10711071
#endif
1072+
}
10721073

10731074
public class EmptyClass
10741075
{

0 commit comments

Comments
 (0)