diff --git a/capnpc-csharp/Model/Annotation.cs b/capnpc-csharp/Model/Annotation.cs index 6dbbd9a..1f5a9c0 100644 --- a/capnpc-csharp/Model/Annotation.cs +++ b/capnpc-csharp/Model/Annotation.cs @@ -1,4 +1,5 @@ - +using System.Diagnostics; + namespace CapnpC.Model { class Annotation : IDefinition @@ -11,6 +12,7 @@ namespace CapnpC.Model public Annotation(ulong id, IHasNestedDefinitions parent) { + Trace.Assert(parent != null); Id = id; DeclaringElement = parent; parent.NestedDefinitions.Add(this); diff --git a/capnpc-csharp/Model/Constant.cs b/capnpc-csharp/Model/Constant.cs index a992ca0..64e9107 100644 --- a/capnpc-csharp/Model/Constant.cs +++ b/capnpc-csharp/Model/Constant.cs @@ -1,4 +1,5 @@ - +using System.Diagnostics; + namespace CapnpC.Model { class Constant : IDefinition @@ -11,6 +12,7 @@ namespace CapnpC.Model public Constant(ulong id, IHasNestedDefinitions parent) { + Trace.Assert(parent != null); Id = id; DeclaringElement = parent; parent.NestedDefinitions.Add(this); diff --git a/capnpc-csharp/Model/GenFile.cs b/capnpc-csharp/Model/GenFile.cs index f912303..15b7918 100644 --- a/capnpc-csharp/Model/GenFile.cs +++ b/capnpc-csharp/Model/GenFile.cs @@ -6,7 +6,7 @@ namespace CapnpC.Model { public ulong Id { get; } public TypeTag Tag { get => TypeTag.File; } - public IHasNestedDefinitions DeclaringElement { get; } + public IHasNestedDefinitions DeclaringElement { get => null; } public string Name { get; set; } public string[] Namespace { get; set; } diff --git a/capnpc-csharp/Model/SchemaModel.cs b/capnpc-csharp/Model/SchemaModel.cs index 4ebafec..4aca4f7 100644 --- a/capnpc-csharp/Model/SchemaModel.cs +++ b/capnpc-csharp/Model/SchemaModel.cs @@ -137,6 +137,7 @@ namespace CapnpC.Model if (def == null) { + Trace.Assert(state.parent != null, $"The {node.GetTypeTag().ToString()} node {node.StrId()} was expected to have a parent."); var typeDef = _typeDefMgr.CreateTypeDef(id, node.GetTypeTag(), state.parent); typeDef.Name = name; def = typeDef; diff --git a/capnpc-csharp/Model/TypeDefinition.cs b/capnpc-csharp/Model/TypeDefinition.cs index 910d4bd..19fb166 100644 --- a/capnpc-csharp/Model/TypeDefinition.cs +++ b/capnpc-csharp/Model/TypeDefinition.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics; using System.Linq; namespace CapnpC.Model { @@ -18,6 +19,7 @@ namespace CapnpC.Model public TypeDefinition(TypeTag tag, ulong id, IHasNestedDefinitions parent) { + Trace.Assert(parent != null); Tag = tag; Id = id; DeclaringElement = parent;