From 9e63e194bb7c4a7a6dfceaab6ac97e8ac2eec76c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Fri, 25 Oct 2019 19:29:44 +0200 Subject: [PATCH] Issue #25 --- .../Capnp.Net.Runtime.Tests.Core21.csproj | 1 + Capnp.Net.Runtime.Tests/Issue25.cs | 890 ++++++++++++++++++ .../TcpRpcAdvancedStuff.cs | 29 + .../TestCapImplementations.cs | 82 +- Capnp.Net.Runtime.Tests/test.cs | 82 +- Capnp.Net.Runtime/DeserializerState.cs | 2 + Capnp.Net.Runtime/Rpc/CapabilityReflection.cs | 3 +- .../Embedded Resources/test.cs | 82 +- CapnpC.CSharp.Generator/CodeGen/GenNames.cs | 2 +- MsBuildGenerationTest/Issue25.capnp | 19 + .../MsBuildGenerationTest.csproj | 4 + 11 files changed, 1111 insertions(+), 85 deletions(-) create mode 100644 Capnp.Net.Runtime.Tests/Issue25.cs create mode 100644 MsBuildGenerationTest/Issue25.capnp diff --git a/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj b/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj index 2492433..eb11e5e 100644 --- a/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj +++ b/Capnp.Net.Runtime.Tests.Core21/Capnp.Net.Runtime.Tests.Core21.csproj @@ -16,6 +16,7 @@ + diff --git a/Capnp.Net.Runtime.Tests/Issue25.cs b/Capnp.Net.Runtime.Tests/Issue25.cs new file mode 100644 index 0000000..7a0da80 --- /dev/null +++ b/Capnp.Net.Runtime.Tests/Issue25.cs @@ -0,0 +1,890 @@ +using Capnp; +using Capnp.Rpc; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace CapnpGen +{ + [TypeId(0xb09c1336dc3ea94eUL), Proxy(typeof(Issue25A_Proxy)), Skeleton(typeof(Issue25A_Skeleton))] + public interface IIssue25A : IDisposable + { + Task MethodA(CancellationToken cancellationToken_ = default); + } + + public class Issue25A_Proxy : Proxy, IIssue25A + { + public async Task MethodA(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new CapnpGen.Issue25A.Params_methodA() + { }; + arg_.serialize(in_); + var d_ = await Call(12726067773386434894UL, 0, in_.Rewrap(), false, cancellationToken_).WhenReturned; + var r_ = CapnpSerializable.Create(d_); + return (r_.Result); + } + } + + public class Issue25A_Skeleton : Skeleton + { + public Issue25A_Skeleton() + { + SetMethodTable(MethodA); + } + + public override ulong InterfaceId => 12726067773386434894UL; + Task MethodA(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.MethodA(cancellationToken_), result => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new CapnpGen.Issue25A.Result_methodA { Result = result }; + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class Issue25A + { + [TypeId(0x994fd8d48f77e57cUL)] + public class Params_methodA : ICapnpSerializable + { + public const UInt64 typeId = 0x994fd8d48f77e57cUL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + [TypeId(0xf504d63e26c4db14UL)] + public class Result_methodA : ICapnpSerializable + { + public const UInt64 typeId = 0xf504d63e26c4db14UL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Result = reader.Result; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Result = Result; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public long Result + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public long Result => ctx.ReadDataLong(0UL, 0L); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(1, 0); + } + + public long Result + { + get => this.ReadDataLong(0UL, 0L); + set => this.WriteData(0UL, value, 0L); + } + } + } + } + + [TypeId(0x9a5c2572c0400979UL), Proxy(typeof(CapHolder_Proxy<>)), Skeleton(typeof(CapHolder_Skeleton<>))] + public interface ICapHolder : IDisposable where TCapType : class + { + Task Cap(CancellationToken cancellationToken_ = default); + } + + public class CapHolder_Proxy : Proxy, ICapHolder where TCapType : class + { + public Task Cap(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc.Params_cap.WRITER>(); + var arg_ = new CapnpGen.CapHolder.Params_cap() + { }; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(11122806354480204153UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create.Result_cap>(d_); + return (r_.Cap); + } + + ); + } + } + + public class CapHolder_Skeleton : Skeleton> where TCapType : class + { + public CapHolder_Skeleton() + { + SetMethodTable(Cap); + } + + public override ulong InterfaceId => 11122806354480204153UL; + Task Cap(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.Cap(cancellationToken_), cap => + { + var s_ = SerializerState.CreateForRpc.Result_cap.WRITER>(); + var r_ = new CapnpGen.CapHolder.Result_cap { Cap = cap }; + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class CapHolder + where TCapType : class + { + [TypeId(0x9fb50287386a4515UL)] + public class Params_cap : ICapnpSerializable + { + public const UInt64 typeId = 0x9fb50287386a4515UL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + [TypeId(0x9b3a7a5298aae998UL)] + public class Result_cap : ICapnpSerializable + { + public const UInt64 typeId = 0x9b3a7a5298aae998UL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = CapnpSerializable.Create(reader.Cap); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap.SetObject(Cap); + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public TCapType Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public DeserializerState Cap => ctx.StructReadPointer(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public DynamicSerializerState Cap + { + get => BuildPointer(0); + set => Link(0, value); + } + } + } + } + + [TypeId(0xc210c6a49d79653cUL), Proxy(typeof(CapHolderA_Proxy)), Skeleton(typeof(CapHolderA_Skeleton))] + public interface ICapHolderA : IDisposable + { + Task Cap(CancellationToken cancellationToken_ = default); + } + + public class CapHolderA_Proxy : Proxy, ICapHolderA + { + public Task Cap(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new CapnpGen.CapHolderA.Params_cap() + { }; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(13983895253304304956UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.Cap); + } + + ); + } + } + + public class CapHolderA_Skeleton : Skeleton + { + public CapHolderA_Skeleton() + { + SetMethodTable(Cap); + } + + public override ulong InterfaceId => 13983895253304304956UL; + Task Cap(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.Cap(cancellationToken_), cap => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new CapnpGen.CapHolderA.Result_cap { Cap = cap }; + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class CapHolderA + { + [TypeId(0xfa15f780f3b1df22UL)] + public class Params_cap : ICapnpSerializable + { + public const UInt64 typeId = 0xfa15f780f3b1df22UL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + [TypeId(0xc2166ff01687f001UL)] + public class Result_cap : ICapnpSerializable + { + public const UInt64 typeId = 0xc2166ff01687f001UL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + Cap = reader.Cap; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.Cap = Cap; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public CapnpGen.IIssue25A Cap + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public CapnpGen.IIssue25A Cap => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public CapnpGen.IIssue25A Cap + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + } + + [TypeId(0xf567e74a1a5cbd2dUL), Proxy(typeof(Issue25B_Proxy)), Skeleton(typeof(Issue25B_Skeleton))] + public interface IIssue25B : IDisposable + { + Task> GetAinCapHolderAnyPointer(CancellationToken cancellationToken_ = default); + Task> GetAinCapHolderGenericA(CancellationToken cancellationToken_ = default); + Task GetAinCapHolderNonGenericA(CancellationToken cancellationToken_ = default); + } + + public class Issue25B_Proxy : Proxy, IIssue25B + { + public Task> GetAinCapHolderAnyPointer(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new CapnpGen.Issue25B.Params_getAinCapHolderAnyPointer() + { }; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(17683356767349423405UL, 0, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.AInCapHolder); + } + + ); + } + + public Task> GetAinCapHolderGenericA(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new CapnpGen.Issue25B.Params_getAinCapHolderGenericA() + { }; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(17683356767349423405UL, 1, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.AInCapHolder); + } + + ); + } + + public Task GetAinCapHolderNonGenericA(CancellationToken cancellationToken_ = default) + { + var in_ = SerializerState.CreateForRpc(); + var arg_ = new CapnpGen.Issue25B.Params_getAinCapHolderNonGenericA() + { }; + arg_.serialize(in_); + return Impatient.MakePipelineAware(Call(17683356767349423405UL, 2, in_.Rewrap(), false, cancellationToken_), d_ => + { + var r_ = CapnpSerializable.Create(d_); + return (r_.AInCapHolder); + } + + ); + } + } + + public class Issue25B_Skeleton : Skeleton + { + public Issue25B_Skeleton() + { + SetMethodTable(GetAinCapHolderAnyPointer, GetAinCapHolderGenericA, GetAinCapHolderNonGenericA); + } + + public override ulong InterfaceId => 17683356767349423405UL; + Task GetAinCapHolderAnyPointer(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.GetAinCapHolderAnyPointer(cancellationToken_), aInCapHolder => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new CapnpGen.Issue25B.Result_getAinCapHolderAnyPointer { AInCapHolder = aInCapHolder }; + r_.serialize(s_); + return s_; + } + + ); + } + + Task GetAinCapHolderGenericA(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.GetAinCapHolderGenericA(cancellationToken_), aInCapHolder => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new CapnpGen.Issue25B.Result_getAinCapHolderGenericA { AInCapHolder = aInCapHolder }; + r_.serialize(s_); + return s_; + } + + ); + } + + Task GetAinCapHolderNonGenericA(DeserializerState d_, CancellationToken cancellationToken_) + { + return Impatient.MaybeTailCall(Impl.GetAinCapHolderNonGenericA(cancellationToken_), aInCapHolder => + { + var s_ = SerializerState.CreateForRpc(); + var r_ = new CapnpGen.Issue25B.Result_getAinCapHolderNonGenericA { AInCapHolder = aInCapHolder }; + r_.serialize(s_); + return s_; + } + + ); + } + } + + public static class Issue25B + { + [TypeId(0xe8d098fdc4452255UL)] + public class Params_getAinCapHolderAnyPointer : ICapnpSerializable + { + public const UInt64 typeId = 0xe8d098fdc4452255UL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + [TypeId(0xf3e141366136b72aUL)] + public class Result_getAinCapHolderAnyPointer : ICapnpSerializable + { + public const UInt64 typeId = 0xf3e141366136b72aUL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + AInCapHolder = reader.AInCapHolder; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.AInCapHolder = AInCapHolder; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public CapnpGen.ICapHolder AInCapHolder + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public CapnpGen.ICapHolder AInCapHolder => ctx.ReadCap>(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public CapnpGen.ICapHolder AInCapHolder + { + get => ReadCap>(0); + set => LinkObject(0, value); + } + } + } + + [TypeId(0x97b7893bbafbac9cUL)] + public class Params_getAinCapHolderGenericA : ICapnpSerializable + { + public const UInt64 typeId = 0x97b7893bbafbac9cUL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + [TypeId(0xca0d4d05609cf941UL)] + public class Result_getAinCapHolderGenericA : ICapnpSerializable + { + public const UInt64 typeId = 0xca0d4d05609cf941UL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + AInCapHolder = reader.AInCapHolder; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.AInCapHolder = AInCapHolder; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public CapnpGen.ICapHolder AInCapHolder + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public CapnpGen.ICapHolder AInCapHolder => ctx.ReadCap>(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public CapnpGen.ICapHolder AInCapHolder + { + get => ReadCap>(0); + set => LinkObject(0, value); + } + } + } + + [TypeId(0xda5cc8f4689eb99fUL)] + public class Params_getAinCapHolderNonGenericA : ICapnpSerializable + { + public const UInt64 typeId = 0xda5cc8f4689eb99fUL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + applyDefaults(); + } + + public void serialize(WRITER writer) + { + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 0); + } + } + } + + [TypeId(0x81a8e7a60710b811UL)] + public class Result_getAinCapHolderNonGenericA : ICapnpSerializable + { + public const UInt64 typeId = 0x81a8e7a60710b811UL; + void ICapnpSerializable.Deserialize(DeserializerState arg_) + { + var reader = READER.create(arg_); + AInCapHolder = reader.AInCapHolder; + applyDefaults(); + } + + public void serialize(WRITER writer) + { + writer.AInCapHolder = AInCapHolder; + } + + void ICapnpSerializable.Serialize(SerializerState arg_) + { + serialize(arg_.Rewrap()); + } + + public void applyDefaults() + { + } + + public CapnpGen.ICapHolderA AInCapHolder + { + get; + set; + } + + public struct READER + { + readonly DeserializerState ctx; + public READER(DeserializerState ctx) + { + this.ctx = ctx; + } + + public static READER create(DeserializerState ctx) => new READER(ctx); + public static implicit operator DeserializerState(READER reader) => reader.ctx; + public static implicit operator READER(DeserializerState ctx) => new READER(ctx); + public CapnpGen.ICapHolderA AInCapHolder => ctx.ReadCap(0); + } + + public class WRITER : SerializerState + { + public WRITER() + { + this.SetStruct(0, 1); + } + + public CapnpGen.ICapHolderA AInCapHolder + { + get => ReadCap(0); + set => LinkObject(0, value); + } + } + } + } +} \ No newline at end of file diff --git a/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs b/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs index 7b8c31c..b708d77 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcAdvancedStuff.cs @@ -143,5 +143,34 @@ namespace Capnp.Net.Runtime.Tests } } } + + [TestMethod] + public void Issue25() + { + using (var server = SetupServer()) + { + server.Main = new Issue25BImpl(); + + using (var client = SetupClient()) + { + client.WhenConnected.Wait(); + + using (var main = client.GetMain()) + { + var capholderAPT = main.GetAinCapHolderAnyPointer(); + Assert.IsTrue(capholderAPT.Wait(MediumNonDbgTimeout)); + var capholderAP = capholderAPT.Result; + var capAPT = capholderAP.Cap(); + Assert.IsTrue(capAPT.Wait(MediumNonDbgTimeout)); + using (var a = ((BareProxy)capAPT.Result).Cast(true)) + { + var r = a.MethodA(); + Assert.IsTrue(r.Wait(MediumNonDbgTimeout)); + Assert.AreEqual(123L, r.Result); + } + } + } + } + } } } diff --git a/Capnp.Net.Runtime.Tests/TestCapImplementations.cs b/Capnp.Net.Runtime.Tests/TestCapImplementations.cs index 94d241a..029ac0f 100644 --- a/Capnp.Net.Runtime.Tests/TestCapImplementations.cs +++ b/Capnp.Net.Runtime.Tests/TestCapImplementations.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Capnproto_test.Capnp.Test; +using CapnpGen; namespace Capnp.Net.Runtime.Tests.GenImpls { @@ -500,7 +501,7 @@ namespace Capnp.Net.Runtime.Tests.GenImpls return ("bar", new TestPipeline.Box() { Cap = new TestExtendsImpl(_counters) }); } - public Task TestPointers(ITestInterface cap, AnyPointer obj, IReadOnlyList list, CancellationToken cancellationToken_) + public Task TestPointers(ITestInterface cap, object obj, IReadOnlyList list, CancellationToken cancellationToken_) { throw new NotImplementedException(); } @@ -776,4 +777,83 @@ namespace Capnp.Net.Runtime.Tests.GenImpls } } #endregion B2 + + #region Issue25 + + class Issue25AImpl : CapnpGen.IIssue25A + { + public void Dispose() + { + } + + public Task MethodA(CancellationToken cancellationToken_ = default) + { + return Task.FromResult(123L); + } + } + + class CapHolderImpl : CapnpGen.ICapHolder + where T: class + { + T _cap; + + public CapHolderImpl(T cap) + { + _cap = cap; + } + + public Task Cap(CancellationToken cancellationToken_ = default) + { + return Task.FromResult(_cap); + } + + public void Dispose() + { + } + } + + class CapHolderAImpl : CapnpGen.ICapHolderA + { + IIssue25A _a; + + public CapHolderAImpl(IIssue25A a) + { + _a = a; + } + + public Task Cap(CancellationToken cancellationToken_ = default) + { + return Task.FromResult(_a); + } + + public void Dispose() + { + } + } + + class Issue25BImpl : CapnpGen.IIssue25B + { + Issue25AImpl _a = new Issue25AImpl(); + + public void Dispose() + { + } + + public Task> GetAinCapHolderAnyPointer(CancellationToken cancellationToken_ = default) + { + return Task.FromResult>(new CapHolderImpl(_a)); + } + + public Task> GetAinCapHolderGenericA(CancellationToken cancellationToken_ = default) + { + return Task.FromResult>(new CapHolderImpl(_a)); + } + + public Task GetAinCapHolderNonGenericA(CancellationToken cancellationToken_ = default) + { + return Task.FromResult(new CapHolderAImpl(_a)); + } + } + + #endregion } diff --git a/Capnp.Net.Runtime.Tests/test.cs b/Capnp.Net.Runtime.Tests/test.cs index 5e02653..e56b8ff 100644 --- a/Capnp.Net.Runtime.Tests/test.cs +++ b/Capnp.Net.Runtime.Tests/test.cs @@ -1223,7 +1223,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - AnyPointerField = CapnpSerializable.Create(reader.AnyPointerField); + AnyPointerField = CapnpSerializable.Create(reader.AnyPointerField); applyDefaults(); } @@ -1241,7 +1241,7 @@ namespace Capnproto_test.Capnp.Test { } - public AnyPointer AnyPointerField + public object AnyPointerField { get; set; @@ -1283,7 +1283,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - AnyStructField = CapnpSerializable.Create(reader.AnyStructField); + AnyStructField = CapnpSerializable.Create(reader.AnyStructField); AnyListField = reader.AnyListField.ToReadOnlyList(_ => (object)_); CapabilityField = reader.CapabilityField; applyDefaults(); @@ -1305,7 +1305,7 @@ namespace Capnproto_test.Capnp.Test { } - public AnyPointer AnyStructField + public object AnyStructField { get; set; @@ -8866,7 +8866,7 @@ namespace Capnproto_test.Capnp.Test var reader = READER.create(arg_); Foo = CapnpSerializable.Create(reader.Foo); Inner = CapnpSerializable.Create.Inner>(reader.Inner); - Inner2 = CapnpSerializable.Create.Inner2>(reader.Inner2); + Inner2 = CapnpSerializable.Create.Inner2>(reader.Inner2); Inner2Bind = CapnpSerializable.Create.Inner2>(reader.Inner2Bind); Inner2Text = CapnpSerializable.Create.Inner2>(reader.Inner2Text); RevFoo = CapnpSerializable.Create(reader.RevFoo); @@ -8904,7 +8904,7 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2 Inner2 + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 Inner2 { get; set; @@ -8941,7 +8941,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public DeserializerState Foo => ctx.StructReadPointer(0); public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER Inner => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2 => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2 => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2Bind => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2Text => ctx.ReadStruct(4, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public DeserializerState RevFoo => ctx.StructReadPointer(5); @@ -8966,9 +8966,9 @@ namespace Capnproto_test.Capnp.Test set => Link(1, value); } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER Inner2 + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER Inner2 { - get => BuildPointer.Inner2.WRITER>(2); + get => BuildPointer.Inner2.WRITER>(2); set => Link(2, value); } @@ -9513,8 +9513,8 @@ namespace Capnproto_test.Capnp.Test Basic = CapnpSerializable.Create>(reader.Basic); Inner = CapnpSerializable.Create.Inner>(reader.Inner); Inner2 = CapnpSerializable.Create.Inner2>(reader.Inner2); - Unspecified = CapnpSerializable.Create>(reader.Unspecified); - UnspecifiedInner = CapnpSerializable.Create.Inner2>(reader.UnspecifiedInner); + Unspecified = CapnpSerializable.Create>(reader.Unspecified); + UnspecifiedInner = CapnpSerializable.Create.Inner2>(reader.UnspecifiedInner); Default = CapnpSerializable.Create>(reader.Default); DefaultInner = CapnpSerializable.Create.Inner>(reader.DefaultInner); DefaultUser = CapnpSerializable.Create(reader.DefaultUser); @@ -9523,7 +9523,7 @@ namespace Capnproto_test.Capnp.Test DefaultWrapper2 = CapnpSerializable.Create(reader.DefaultWrapper2); AliasFoo = CapnpSerializable.Create(reader.AliasFoo); AliasInner = CapnpSerializable.Create.Inner>(reader.AliasInner); - AliasInner2 = CapnpSerializable.Create.Inner2>(reader.AliasInner2); + AliasInner2 = CapnpSerializable.Create.Inner2>(reader.AliasInner2); AliasInner2Bind = CapnpSerializable.Create.Inner2>>(reader.AliasInner2Bind); AliasInner2Text = CapnpSerializable.Create.Inner2>(reader.AliasInner2Text); AliasRev = reader.AliasRev; @@ -9739,9 +9739,9 @@ namespace Capnproto_test.Capnp.Test { }, Inner2 = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() { }, - Unspecified = new Capnproto_test.Capnp.Test.TestGenerics() + Unspecified = new Capnproto_test.Capnp.Test.TestGenerics() { }, - UnspecifiedInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + UnspecifiedInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() { }, Default = new Capnproto_test.Capnp.Test.TestGenerics() { }, @@ -9759,7 +9759,7 @@ namespace Capnproto_test.Capnp.Test { }, AliasInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner() { }, - AliasInner2 = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + AliasInner2 = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() { }, AliasInner2Bind = new Capnproto_test.Capnp.Test.TestGenerics.Inner2>() { }, @@ -9951,7 +9951,7 @@ namespace Capnproto_test.Capnp.Test Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() { } }; - AliasInner2 = AliasInner2 ?? new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + AliasInner2 = AliasInner2 ?? new Capnproto_test.Capnp.Test.TestGenerics.Inner2() { Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() { }, @@ -10176,7 +10176,7 @@ namespace Capnproto_test.Capnp.Test }, Bar = new uint[] { } }, - Inner2 = new Capnproto_test.Capnp.Test.TestGenerics>.Inner2() + Inner2 = new Capnproto_test.Capnp.Test.TestGenerics>.Inner2() { Bar = new uint[] { }, InnerBound = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() @@ -10338,13 +10338,13 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestGenerics Unspecified + public Capnproto_test.Capnp.Test.TestGenerics Unspecified { get; set; } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2 UnspecifiedInner + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 UnspecifiedInner { get; set; @@ -10398,7 +10398,7 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2 AliasInner2 + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 AliasInner2 { get; set; @@ -10454,8 +10454,8 @@ namespace Capnproto_test.Capnp.Test public Capnproto_test.Capnp.Test.TestGenerics.READER Basic => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestGenerics.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER Inner => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2 => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); - public Capnproto_test.Capnp.Test.TestGenerics.READER Unspecified => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestGenerics.READER.create); - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER UnspecifiedInner => ctx.ReadStruct(4, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.READER Unspecified => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestGenerics.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER UnspecifiedInner => ctx.ReadStruct(4, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.READER Default => ctx.ReadStruct(5, Capnproto_test.Capnp.Test.TestGenerics.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER DefaultInner => ctx.ReadStruct(6, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); public Capnproto_test.Capnp.Test.TestUseGenerics.READER DefaultUser => ctx.ReadStruct(7, Capnproto_test.Capnp.Test.TestUseGenerics.READER.create); @@ -10464,7 +10464,7 @@ namespace Capnproto_test.Capnp.Test public Capnproto_test.Capnp.Test.TestGenericsWrapper2.READER DefaultWrapper2 => ctx.ReadStruct(10, Capnproto_test.Capnp.Test.TestGenericsWrapper2.READER.create); public Capnproto_test.Capnp.Test.TestAllTypes.READER AliasFoo => ctx.ReadStruct(11, Capnproto_test.Capnp.Test.TestAllTypes.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER AliasInner => ctx.ReadStruct(12, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER AliasInner2 => ctx.ReadStruct(13, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER AliasInner2 => ctx.ReadStruct(13, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2>.READER AliasInner2Bind => ctx.ReadStruct(14, Capnproto_test.Capnp.Test.TestGenerics.Inner2>.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER AliasInner2Text => ctx.ReadStruct(15, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public string AliasRev => ctx.ReadText(16, "text"); @@ -10498,15 +10498,15 @@ namespace Capnproto_test.Capnp.Test set => Link(2, value); } - public Capnproto_test.Capnp.Test.TestGenerics.WRITER Unspecified + public Capnproto_test.Capnp.Test.TestGenerics.WRITER Unspecified { - get => BuildPointer.WRITER>(3); + get => BuildPointer.WRITER>(3); set => Link(3, value); } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER UnspecifiedInner + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER UnspecifiedInner { - get => BuildPointer.Inner2.WRITER>(4); + get => BuildPointer.Inner2.WRITER>(4); set => Link(4, value); } @@ -10558,9 +10558,9 @@ namespace Capnproto_test.Capnp.Test set => Link(12, value); } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER AliasInner2 + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER AliasInner2 { - get => BuildPointer.Inner2.WRITER>(13); + get => BuildPointer.Inner2.WRITER>(13); set => Link(13, value); } @@ -10699,9 +10699,9 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - AnyKindAsStruct = CapnpSerializable.Create(reader.AnyKindAsStruct); - AnyStructAsStruct = CapnpSerializable.Create(reader.AnyStructAsStruct); - AnyKindAsList = CapnpSerializable.Create(reader.AnyKindAsList); + AnyKindAsStruct = CapnpSerializable.Create(reader.AnyKindAsStruct); + AnyStructAsStruct = CapnpSerializable.Create(reader.AnyStructAsStruct); + AnyKindAsList = CapnpSerializable.Create(reader.AnyKindAsList); AnyListAsList = reader.AnyListAsList.ToReadOnlyList(_ => (object)_); applyDefaults(); } @@ -10723,19 +10723,19 @@ namespace Capnproto_test.Capnp.Test { } - public AnyPointer AnyKindAsStruct + public object AnyKindAsStruct { get; set; } - public AnyPointer AnyStructAsStruct + public object AnyStructAsStruct { get; set; } - public AnyPointer AnyKindAsList + public object AnyKindAsList { get; set; @@ -11591,7 +11591,7 @@ namespace Capnproto_test.Capnp.Test public interface ITestPipeline : IDisposable { Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default); - Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, AnyPointer obj, IReadOnlyList list, CancellationToken cancellationToken_ = default); + Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, object obj, IReadOnlyList list, CancellationToken cancellationToken_ = default); Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default); } @@ -11612,7 +11612,7 @@ namespace Capnproto_test.Capnp.Test ); } - public async Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, AnyPointer obj, IReadOnlyList list, CancellationToken cancellationToken_ = default) + public async Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, object obj, IReadOnlyList list, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc(); var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_testPointers() @@ -11964,7 +11964,7 @@ namespace Capnproto_test.Capnp.Test { var reader = READER.create(arg_); Cap = reader.Cap; - Obj = CapnpSerializable.Create(reader.Obj); + Obj = CapnpSerializable.Create(reader.Obj); List = reader.List; applyDefaults(); } @@ -11991,7 +11991,7 @@ namespace Capnproto_test.Capnp.Test set; } - public AnyPointer Obj + public object Obj { get; set; @@ -16294,7 +16294,7 @@ namespace Capnproto_test.Capnp.Test { var reader = READER.create(arg_); HostId = CapnpSerializable.Create(reader.HostId); - ObjectId = CapnpSerializable.Create(reader.ObjectId); + ObjectId = CapnpSerializable.Create(reader.ObjectId); applyDefaults(); } @@ -16319,7 +16319,7 @@ namespace Capnproto_test.Capnp.Test set; } - public AnyPointer ObjectId + public object ObjectId { get; set; diff --git a/Capnp.Net.Runtime/DeserializerState.cs b/Capnp.Net.Runtime/DeserializerState.cs index 5fed754..73f44df 100644 --- a/Capnp.Net.Runtime/DeserializerState.cs +++ b/Capnp.Net.Runtime/DeserializerState.cs @@ -355,7 +355,9 @@ namespace Capnp continue; case PointerKind.Other: + var tmp = Caps; this = default; + Caps = tmp; Kind = ObjectKind.Capability; BytesTraversedOrData = pointer.CapabilityIndex; return; diff --git a/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs b/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs index 0ae96f1..2cde6e6 100644 --- a/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs +++ b/Capnp.Net.Runtime/Rpc/CapabilityReflection.cs @@ -99,6 +99,7 @@ namespace Capnp.Rpc static CapabilityReflection() { _proxyMap.Add(typeof(BareProxy), new ProxyFactory()); + _proxyMap.Add(typeof(object), new ProxyFactory()); } static SkeletonFactory CreateMonoSkeletonFactory(SkeletonAttribute attr, Type[] genericArguments) @@ -185,7 +186,7 @@ namespace Capnp.Rpc Type proxyClass = attrs[0].ProxyClass; Type[] genericArguments = type.GetGenericArguments(); if (genericArguments.Length > 0) - proxyClass = proxyClass.MakeGenericType(proxyClass); + proxyClass = proxyClass.MakeGenericType(genericArguments); return (ProxyFactory)Activator.CreateInstance( typeof(ProxyFactory<>) diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs index b2660f6..80b2310 100644 --- a/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs +++ b/CapnpC.CSharp.Generator.Tests/Embedded Resources/test.cs @@ -1124,7 +1124,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - AnyPointerField = CapnpSerializable.Create(reader.AnyPointerField); + AnyPointerField = CapnpSerializable.Create(reader.AnyPointerField); applyDefaults(); } @@ -1142,7 +1142,7 @@ namespace Capnproto_test.Capnp.Test { } - public AnyPointer AnyPointerField + public object AnyPointerField { get; set; @@ -1184,7 +1184,7 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - AnyStructField = CapnpSerializable.Create(reader.AnyStructField); + AnyStructField = CapnpSerializable.Create(reader.AnyStructField); AnyListField = reader.AnyListField.ToReadOnlyList(_ => (object)_); CapabilityField = reader.CapabilityField; applyDefaults(); @@ -1206,7 +1206,7 @@ namespace Capnproto_test.Capnp.Test { } - public AnyPointer AnyStructField + public object AnyStructField { get; set; @@ -8730,7 +8730,7 @@ namespace Capnproto_test.Capnp.Test var reader = READER.create(arg_); Foo = CapnpSerializable.Create(reader.Foo); Inner = CapnpSerializable.Create.Inner>(reader.Inner); - Inner2 = CapnpSerializable.Create.Inner2>(reader.Inner2); + Inner2 = CapnpSerializable.Create.Inner2>(reader.Inner2); Inner2Bind = CapnpSerializable.Create.Inner2>(reader.Inner2Bind); Inner2Text = CapnpSerializable.Create.Inner2>(reader.Inner2Text); RevFoo = CapnpSerializable.Create(reader.RevFoo); @@ -8768,7 +8768,7 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2 Inner2 + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 Inner2 { get; set; @@ -8805,7 +8805,7 @@ namespace Capnproto_test.Capnp.Test public static implicit operator READER(DeserializerState ctx) => new READER(ctx); public DeserializerState Foo => ctx.StructReadPointer(0); public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER Inner => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2 => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2 => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2Bind => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2Text => ctx.ReadStruct(4, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public DeserializerState RevFoo => ctx.StructReadPointer(5); @@ -8830,9 +8830,9 @@ namespace Capnproto_test.Capnp.Test set => Link(1, value); } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER Inner2 + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER Inner2 { - get => BuildPointer.Inner2.WRITER>(2); + get => BuildPointer.Inner2.WRITER>(2); set => Link(2, value); } @@ -9377,8 +9377,8 @@ namespace Capnproto_test.Capnp.Test Basic = CapnpSerializable.Create>(reader.Basic); Inner = CapnpSerializable.Create.Inner>(reader.Inner); Inner2 = CapnpSerializable.Create.Inner2>(reader.Inner2); - Unspecified = CapnpSerializable.Create>(reader.Unspecified); - UnspecifiedInner = CapnpSerializable.Create.Inner2>(reader.UnspecifiedInner); + Unspecified = CapnpSerializable.Create>(reader.Unspecified); + UnspecifiedInner = CapnpSerializable.Create.Inner2>(reader.UnspecifiedInner); Default = CapnpSerializable.Create>(reader.Default); DefaultInner = CapnpSerializable.Create.Inner>(reader.DefaultInner); DefaultUser = CapnpSerializable.Create(reader.DefaultUser); @@ -9387,7 +9387,7 @@ namespace Capnproto_test.Capnp.Test DefaultWrapper2 = CapnpSerializable.Create(reader.DefaultWrapper2); AliasFoo = CapnpSerializable.Create(reader.AliasFoo); AliasInner = CapnpSerializable.Create.Inner>(reader.AliasInner); - AliasInner2 = CapnpSerializable.Create.Inner2>(reader.AliasInner2); + AliasInner2 = CapnpSerializable.Create.Inner2>(reader.AliasInner2); AliasInner2Bind = CapnpSerializable.Create.Inner2>>(reader.AliasInner2Bind); AliasInner2Text = CapnpSerializable.Create.Inner2>(reader.AliasInner2Text); AliasRev = reader.AliasRev; @@ -9448,8 +9448,8 @@ namespace Capnproto_test.Capnp.Test {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Rev = new Capnproto_test.Capnp.Test.TestGenerics() {}, List = new Capnproto_test.Capnp.Test.TestGenerics.Inner[]{}}, Inner = new Capnproto_test.Capnp.Test.TestGenerics.Inner() {}, Inner2 = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() - {}, Unspecified = new Capnproto_test.Capnp.Test.TestGenerics() - {}, UnspecifiedInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + {}, Unspecified = new Capnproto_test.Capnp.Test.TestGenerics() + {}, UnspecifiedInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() {}, Default = new Capnproto_test.Capnp.Test.TestGenerics() {}, DefaultInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner() {}, DefaultUser = new Capnproto_test.Capnp.Test.TestUseGenerics() @@ -9458,7 +9458,7 @@ namespace Capnproto_test.Capnp.Test {}, DefaultWrapper2 = new Capnproto_test.Capnp.Test.TestGenericsWrapper2() {}, AliasFoo = new Capnproto_test.Capnp.Test.TestAllTypes() {}, AliasInner = new Capnproto_test.Capnp.Test.TestGenerics.Inner() - {}, AliasInner2 = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + {}, AliasInner2 = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() {}, AliasInner2Bind = new Capnproto_test.Capnp.Test.TestGenerics.Inner2>() {}, AliasInner2Text = new Capnproto_test.Capnp.Test.TestGenerics.Inner2() {}, AliasRev = null, UseAliases = new Capnproto_test.Capnp.Test.TestGenerics>.UseAliases() @@ -9487,7 +9487,7 @@ namespace Capnproto_test.Capnp.Test {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() {}}; - AliasInner2 = AliasInner2 ?? new Capnproto_test.Capnp.Test.TestGenerics.Inner2() + AliasInner2 = AliasInner2 ?? new Capnproto_test.Capnp.Test.TestGenerics.Inner2() {Bar = new Capnproto_test.Capnp.Test.TestAnyPointer() {}, InnerBound = new Capnproto_test.Capnp.Test.TestGenerics.Inner() {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() @@ -9518,7 +9518,7 @@ namespace Capnproto_test.Capnp.Test {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Inner = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() - {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new uint[]{}}, Inner2 = new Capnproto_test.Capnp.Test.TestGenerics>.Inner2() + {}, EnumField = Capnproto_test.Capnp.Test.TestEnum.foo, VoidList = 0, BoolList = new bool[]{}, Int8List = new sbyte[]{}, Int16List = new short[]{}, Int32List = new int[]{}, Int64List = new long[]{}, UInt8List = new byte[]{}, UInt16List = new ushort[]{}, UInt32List = new uint[]{}, UInt64List = new ulong[]{}, Float32List = new float[]{}, Float64List = new double[]{}, TextList = new string[]{}, DataList = new IReadOnlyList[]{}, StructList = new Capnproto_test.Capnp.Test.TestAllTypes[]{}, EnumList = new Capnproto_test.Capnp.Test.TestEnum[]{}, InterfaceList = 0}, Bar = new uint[]{}}, Inner2 = new Capnproto_test.Capnp.Test.TestGenerics>.Inner2() {Bar = new uint[]{}, InnerBound = new Capnproto_test.Capnp.Test.TestGenerics>.Inner() {Foo = new Capnproto_test.Capnp.Test.TestAllTypes() {BoolField = false, Int8Field = 0, Int16Field = 123, Int32Field = 0, Int64Field = 0L, UInt8Field = 0, UInt16Field = 0, UInt32Field = 0U, UInt64Field = 0UL, Float32Field = 0F, Float64Field = 0, TextField = null, DataField = new byte[]{}, StructField = new Capnproto_test.Capnp.Test.TestAllTypes() @@ -9554,13 +9554,13 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestGenerics Unspecified + public Capnproto_test.Capnp.Test.TestGenerics Unspecified { get; set; } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2 UnspecifiedInner + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 UnspecifiedInner { get; set; @@ -9614,7 +9614,7 @@ namespace Capnproto_test.Capnp.Test set; } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2 AliasInner2 + public Capnproto_test.Capnp.Test.TestGenerics.Inner2 AliasInner2 { get; set; @@ -9670,8 +9670,8 @@ namespace Capnproto_test.Capnp.Test public Capnproto_test.Capnp.Test.TestGenerics.READER Basic => ctx.ReadStruct(0, Capnproto_test.Capnp.Test.TestGenerics.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER Inner => ctx.ReadStruct(1, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER Inner2 => ctx.ReadStruct(2, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); - public Capnproto_test.Capnp.Test.TestGenerics.READER Unspecified => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestGenerics.READER.create); - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER UnspecifiedInner => ctx.ReadStruct(4, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.READER Unspecified => ctx.ReadStruct(3, Capnproto_test.Capnp.Test.TestGenerics.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER UnspecifiedInner => ctx.ReadStruct(4, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.READER Default => ctx.ReadStruct(5, Capnproto_test.Capnp.Test.TestGenerics.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER DefaultInner => ctx.ReadStruct(6, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); public Capnproto_test.Capnp.Test.TestUseGenerics.READER DefaultUser => ctx.ReadStruct(7, Capnproto_test.Capnp.Test.TestUseGenerics.READER.create); @@ -9680,7 +9680,7 @@ namespace Capnproto_test.Capnp.Test public Capnproto_test.Capnp.Test.TestGenericsWrapper2.READER DefaultWrapper2 => ctx.ReadStruct(10, Capnproto_test.Capnp.Test.TestGenericsWrapper2.READER.create); public Capnproto_test.Capnp.Test.TestAllTypes.READER AliasFoo => ctx.ReadStruct(11, Capnproto_test.Capnp.Test.TestAllTypes.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner.READER AliasInner => ctx.ReadStruct(12, Capnproto_test.Capnp.Test.TestGenerics.Inner.READER.create); - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER AliasInner2 => ctx.ReadStruct(13, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER AliasInner2 => ctx.ReadStruct(13, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2>.READER AliasInner2Bind => ctx.ReadStruct(14, Capnproto_test.Capnp.Test.TestGenerics.Inner2>.READER.create); public Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER AliasInner2Text => ctx.ReadStruct(15, Capnproto_test.Capnp.Test.TestGenerics.Inner2.READER.create); public string AliasRev => ctx.ReadText(16, "text"); @@ -9714,15 +9714,15 @@ namespace Capnproto_test.Capnp.Test set => Link(2, value); } - public Capnproto_test.Capnp.Test.TestGenerics.WRITER Unspecified + public Capnproto_test.Capnp.Test.TestGenerics.WRITER Unspecified { - get => BuildPointer.WRITER>(3); + get => BuildPointer.WRITER>(3); set => Link(3, value); } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER UnspecifiedInner + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER UnspecifiedInner { - get => BuildPointer.Inner2.WRITER>(4); + get => BuildPointer.Inner2.WRITER>(4); set => Link(4, value); } @@ -9774,9 +9774,9 @@ namespace Capnproto_test.Capnp.Test set => Link(12, value); } - public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER AliasInner2 + public Capnproto_test.Capnp.Test.TestGenerics.Inner2.WRITER AliasInner2 { - get => BuildPointer.Inner2.WRITER>(13); + get => BuildPointer.Inner2.WRITER>(13); set => Link(13, value); } @@ -9915,9 +9915,9 @@ namespace Capnproto_test.Capnp.Test void ICapnpSerializable.Deserialize(DeserializerState arg_) { var reader = READER.create(arg_); - AnyKindAsStruct = CapnpSerializable.Create(reader.AnyKindAsStruct); - AnyStructAsStruct = CapnpSerializable.Create(reader.AnyStructAsStruct); - AnyKindAsList = CapnpSerializable.Create(reader.AnyKindAsList); + AnyKindAsStruct = CapnpSerializable.Create(reader.AnyKindAsStruct); + AnyStructAsStruct = CapnpSerializable.Create(reader.AnyStructAsStruct); + AnyKindAsList = CapnpSerializable.Create(reader.AnyKindAsList); AnyListAsList = reader.AnyListAsList.ToReadOnlyList(_ => (object)_); applyDefaults(); } @@ -9939,19 +9939,19 @@ namespace Capnproto_test.Capnp.Test { } - public AnyPointer AnyKindAsStruct + public object AnyKindAsStruct { get; set; } - public AnyPointer AnyStructAsStruct + public object AnyStructAsStruct { get; set; } - public AnyPointer AnyKindAsList + public object AnyKindAsList { get; set; @@ -10807,7 +10807,7 @@ namespace Capnproto_test.Capnp.Test public interface ITestPipeline : IDisposable { Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default); - Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, AnyPointer obj, IReadOnlyList list, CancellationToken cancellationToken_ = default); + Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, object obj, IReadOnlyList list, CancellationToken cancellationToken_ = default); Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default); } @@ -10828,7 +10828,7 @@ namespace Capnproto_test.Capnp.Test ); } - public async Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, AnyPointer obj, IReadOnlyList list, CancellationToken cancellationToken_ = default) + public async Task TestPointers(Capnproto_test.Capnp.Test.ITestInterface cap, object obj, IReadOnlyList list, CancellationToken cancellationToken_ = default) { var in_ = SerializerState.CreateForRpc(); var arg_ = new Capnproto_test.Capnp.Test.TestPipeline.Params_testPointers() @@ -11180,7 +11180,7 @@ namespace Capnproto_test.Capnp.Test { var reader = READER.create(arg_); Cap = reader.Cap; - Obj = CapnpSerializable.Create(reader.Obj); + Obj = CapnpSerializable.Create(reader.Obj); List = reader.List; applyDefaults(); } @@ -11207,7 +11207,7 @@ namespace Capnproto_test.Capnp.Test set; } - public AnyPointer Obj + public object Obj { get; set; @@ -15510,7 +15510,7 @@ namespace Capnproto_test.Capnp.Test { var reader = READER.create(arg_); HostId = CapnpSerializable.Create(reader.HostId); - ObjectId = CapnpSerializable.Create(reader.ObjectId); + ObjectId = CapnpSerializable.Create(reader.ObjectId); applyDefaults(); } @@ -15535,7 +15535,7 @@ namespace Capnproto_test.Capnp.Test set; } - public AnyPointer ObjectId + public object ObjectId { get; set; diff --git a/CapnpC.CSharp.Generator/CodeGen/GenNames.cs b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs index c878b04..1587449 100644 --- a/CapnpC.CSharp.Generator/CodeGen/GenNames.cs +++ b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs @@ -406,7 +406,7 @@ namespace CapnpC.CSharp.Generator.CodeGen } else { - return SyntaxHelpers.Type(); + return SyntaxHelpers.Type(); } default: diff --git a/MsBuildGenerationTest/Issue25.capnp b/MsBuildGenerationTest/Issue25.capnp new file mode 100644 index 0000000..9d8f9cb --- /dev/null +++ b/MsBuildGenerationTest/Issue25.capnp @@ -0,0 +1,19 @@ +@0xa53fcfef8b306bfb; + +interface Issue25A { + methodA @0 () -> (result :Int64); +} + +interface CapHolder(CapType) { + cap @0 () -> (cap :CapType); +} + +interface CapHolderA { + cap @0 () -> (cap :Issue25A); +} + +interface Issue25B { + getAinCapHolderAnyPointer @0 () -> (aInCapHolder :CapHolder); + getAinCapHolderGenericA @1 () -> (aInCapHolder :CapHolder(Issue25A)); + getAinCapHolderNonGenericA @2 () -> (aInCapHolder :CapHolderA); +} diff --git a/MsBuildGenerationTest/MsBuildGenerationTest.csproj b/MsBuildGenerationTest/MsBuildGenerationTest.csproj index 930a851..22ff1a8 100644 --- a/MsBuildGenerationTest/MsBuildGenerationTest.csproj +++ b/MsBuildGenerationTest/MsBuildGenerationTest.csproj @@ -16,6 +16,10 @@ + + + +