From 89c02b47db292e2f5dd80d23c53b16f14953281a Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 11 Oct 2022 09:02:41 -0700 Subject: [PATCH] allow TypeDef to append StructA and UnionA --- src/type.cpp | 4 ++-- test/testtype.cpp | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/type.cpp b/src/type.cpp index d02cf03..a316ed7 100644 --- a/src/type.cpp +++ b/src/type.cpp @@ -341,8 +341,8 @@ Member TypeDef::as(const std::string& name) const std::shared_ptr TypeDef::_append_start() { - if(!top || (top->code!=TypeCode::Struct && top->code!=TypeCode::Union)) - throw std::logic_error("May only append to Struct or Union"); + if(!top || (top->code.scalarOf()!=TypeCode::Struct && top->code.scalarOf()!=TypeCode::Union)) + throw std::logic_error("May only append to Struct, Union, StructA, or UnionA"); std::shared_ptr edit; if(top.use_count()==1u) { diff --git a/test/testtype.cpp b/test/testtype.cpp index d57834b..5a90891 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -345,6 +345,40 @@ void testTypeDefDynamic() " double value = 0\n" "}\n"); } + { + TypeDef def(TypeCode::StructA, "simple_t", {}); + + def += mem; + + auto val = def.create(); + shared_array arr(1); + arr[0] = val.allocMember().update("value", 42); + val = arr.freeze(); + + testTrue(val.valid()); + testStrEq(std::string(SB()< arr(1); + arr[0] = val.allocMember().update("->value", 42); + val = arr.freeze(); + + testTrue(val.valid()); + testStrEq(std::string(SB()<