schema compile CHANGE support to refine presence in uses/grouping data
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index 0a8ed33..1e2f4e7 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -3535,6 +3535,17 @@
                    "Invalid refine of default in \"%s\" - the node is mandatory.", rfn->nodeid);
             goto error;
         }
+
+        /* presence */
+        if (rfn->presence) {
+            if (node->nodetype != LYS_CONTAINER) {
+                LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SEMANTICS,
+                       "Invalid refine of presence statement in \"%s\" - %s cannot hold the presence statement.",
+                       rfn->nodeid, lys_nodetype2str(node->nodetype));
+                goto error;
+            }
+            node->flags |= LYS_PRESENCE;
+        }
     }
     /* fix connection of the children nodes from fake context node back into the parent */
     if (context_node_fake.child) {
diff --git a/tests/src/test_tree_schema_compile.c b/tests/src/test_tree_schema_compile.c
index f6df95e..ea528c2 100644
--- a/tests/src/test_tree_schema_compile.c
+++ b/tests/src/test_tree_schema_compile.c
@@ -2309,7 +2309,7 @@
                                         "refine c/ll {default hello;default world;}"
                                         "refine c/ch {default b;config true;}"
                                         "refine c/x {mandatory false;}"
-                                        "refine c/c {config true;}}}", LYS_IN_YANG));
+                                        "refine c/c {config true;presence indispensable;}}}", LYS_IN_YANG));
     assert_int_equal(LY_SUCCESS, lys_compile(mod, 0));
     assert_non_null((parent = mod->compiled->data));
     assert_int_equal(LYS_CONTAINER, parent->nodetype);
@@ -2414,6 +2414,11 @@
     assert_int_equal(LY_EVALID, lys_compile(mod, 0));
     logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status.");
 
+    assert_non_null(mod = lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;import grp {prefix g;}"
+                                        "uses g:grp {refine c/x {presence nonsence;}}}", LYS_IN_YANG));
+    assert_int_equal(LY_EVALID, lys_compile(mod, 0));
+    logbuf_assert("Invalid refine of presence statement in \"c/x\" - leaf cannot hold the presence statement.");
+
     *state = NULL;
     ly_ctx_destroy(ctx, NULL);
 }