Skip to content

Conform option does not pay attention on language features #8169

@blindspotbounty

Description

@blindspotbounty

I was trying to use --conform option while have some unions with structures inside.

Simplified fbs file:

namespace DataModel;

// Wrapping structures for union
struct A {
    a:int;
}

struct B {
    b:double;
}

// Unions
union FooUnion {
    a:A,
    b:B
}

table Msg {
    foo:FooUnion;
}

If I generate code from this DM it works:

flatc --swift DM.fbs

But if I want to check conformance for this file:

$ flatc --swift DM.fbs --conform DM.fbs --swift                   

error:
  <path...>/DM.fbs:23: 0: error: only tables can be union elements in the generated language: a

I guess that conformance parser should copy options around this place:

diff --git a/src/flatc.cpp b/src/flatc.cpp
index 4bc88eb1..e5f96b46 100644
--- a/src/flatc.cpp
+++ b/src/flatc.cpp
@@ -727,6 +727,7 @@ void FlatCompiler::ValidateOptions(const FlatCOptions &options) {
 flatbuffers::Parser FlatCompiler::GetConformParser(
     const FlatCOptions &options) {
   flatbuffers::Parser conform_parser;
+  conform_parser.opts = options.opts;
   if (!options.conform_to_schema.empty()) {
     std::string contents;
     if (!flatbuffers::LoadFile(options.conform_to_schema.c_str(), true,
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp
index d01e18ef..0580808d 100644

Then conformance works correctly.
Not sure if it is a bug or some intentional behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions