@@ -2134,10 +2134,12 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
21342134 const struct lysp_type * type_p , struct lysc_type * * type , const char * * units , struct lysp_qname * * dflt )
21352135{
21362136 LY_ERR ret = LY_SUCCESS ;
2137- ly_bool dummyloops = 0 ;
2137+ ly_bool dummyloops = 0 , has_leafref ;
21382138 struct lys_type_item * tctx , * tctx_prev = NULL , * tctx_iter ;
21392139 LY_DATA_TYPE basetype = LY_TYPE_UNKNOWN ;
21402140 struct lysc_type * base = NULL ;
2141+ struct lysc_type_union * base_un ;
2142+ LY_ARRAY_COUNT_TYPE u ;
21412143 struct ly_set tpdf_chain = {0 };
21422144 struct lyplg_type * plugin ;
21432145
@@ -2307,8 +2309,25 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
23072309 /* remove the processed typedef contexts from the stack for circular check */
23082310 ctx -> tpdf_chain .count = ctx -> tpdf_chain .count - tpdf_chain .count ;
23092311
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+
23102329 /* 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 ) {
23122331 /* leaf type has changes that need to be compiled into the type */
23132332 plugin = base ? base -> plugin : lyplg_type_plugin_find (ctx -> ctx , "" , NULL , ly_data_type2str [basetype ]);
23142333 ret = lys_compile_type_ (ctx , context_pnode , context_flags , context_name , (struct lysp_type * )type_p , basetype ,
0 commit comments