CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
358 stars 284 forks source link

if-featured enumeration doesn't work when there's another enumeration #1737

Closed syyyr closed 2 years ago

syyyr commented 2 years ago

Hi, I found this bug that happens since f4fa90dd. When trying to print all enums of the enum2 enumeration, it also prints the ifFeaturedEnum. If I remove the enum1 leaf, everything works correctly.

#include <iostream>
#include <libyang/libyang.h>
#include <span>
#include <string>
const char* my = R"(
module my {
    yang-version 1.1;
    namespace "http://example.com/example";
    prefix coze;

    leaf enum1 {
        type enumeration {
            enum a;
        }
    }

    feature myFeature;

    leaf enum2 {
        type enumeration {
            enum ifFeaturedEnum {
                if-feature "myFeature";
            }
            enum two;
        }
    }
})";

int main(int argc, char* argv[])
{
    ly_ctx* ctx;
    ly_ctx_new(nullptr, 0, &ctx);
    lys_module* mod;
    lys_parse_mem(ctx, my, LYS_IN_YANG, &mod);
    auto enum_schema = reinterpret_cast<const lysc_node_leaf*>(lys_find_path(ctx, nullptr, "/my:enum2", false));
    auto type_enum = reinterpret_cast<lysc_type_enum*>(enum_schema->type);
    for (const auto& it : std::span(type_enum->enums, LY_ARRAY_COUNT(type_enum->enums))) {
        std::cerr << "it.name = " << it.name << "\n";
    }
    ly_ctx_destroy(ctx);

    return 0;
}
michalvasko commented 2 years ago

My bad, should be fixed now.

syyyr commented 2 years ago

Thanks.