@@ -2134,10 +2134,12 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
2134
2134
const struct lysp_type * type_p , struct lysc_type * * type , const char * * units , struct lysp_qname * * dflt )
2135
2135
{
2136
2136
LY_ERR ret = LY_SUCCESS ;
2137
- ly_bool dummyloops = 0 ;
2137
+ ly_bool dummyloops = 0 , has_leafref ;
2138
2138
struct lys_type_item * tctx , * tctx_prev = NULL , * tctx_iter ;
2139
2139
LY_DATA_TYPE basetype = LY_TYPE_UNKNOWN ;
2140
2140
struct lysc_type * base = NULL ;
2141
+ struct lysc_type_union * base_un ;
2142
+ LY_ARRAY_COUNT_TYPE u ;
2141
2143
struct ly_set tpdf_chain = {0 };
2142
2144
struct lyplg_type * plugin ;
2143
2145
@@ -2307,8 +2309,25 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
2307
2309
/* remove the processed typedef contexts from the stack for circular check */
2308
2310
ctx -> tpdf_chain .count = ctx -> tpdf_chain .count - tpdf_chain .count ;
2309
2311
2312
+ /* learn whether the type has a leafref, in which case it cannot be shared because it may resolve to a different
2313
+ * real type for every instantiation */
2314
+ has_leafref = 0 ;
2315
+ if (basetype == LY_TYPE_LEAFREF ) {
2316
+ /* leafref type */
2317
+ has_leafref = 1 ;
2318
+ } else if ((basetype == LY_TYPE_UNION ) && base ) {
2319
+ /* union with a leafref */
2320
+ base_un = (struct lysc_type_union * )base ;
2321
+ LY_ARRAY_FOR (base_un -> types , u ) {
2322
+ if (base_un -> types [u ]-> basetype == LY_TYPE_LEAFREF ) {
2323
+ has_leafref = 1 ;
2324
+ break ;
2325
+ }
2326
+ }
2327
+ }
2328
+
2310
2329
/* process the type definition in leaf */
2311
- if (type_p -> flags || type_p -> exts || !base || ( basetype == LY_TYPE_LEAFREF ) ) {
2330
+ if (type_p -> flags || type_p -> exts || !base || has_leafref ) {
2312
2331
/* leaf type has changes that need to be compiled into the type */
2313
2332
plugin = base ? base -> plugin : lyplg_type_plugin_find (ctx -> ctx , "" , NULL , ly_data_type2str [basetype ]);
2314
2333
ret = lys_compile_type_ (ctx , context_pnode , context_flags , context_name , (struct lysp_type * )type_p , basetype ,
0 commit comments