schema compile REFACTOR resolve unres at the end of module compilation

So that it can then be changed to resolve unres
at the end of all newly implemented modules compilation.
diff --git a/src/schema_compile.c b/src/schema_compile.c
index 6ac18af..da1eaa9 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -1648,13 +1648,10 @@
 
         COMPILE_EXTS_GOTO(&ctx, submod->exts, mod_c->exts, mod_c, LYEXT_PAR_MODULE, ret, error);
     }
-
-    /* finish compilation for all unresolved items in the context */
-    LY_CHECK_GOTO(ret = lys_compile_unres(&ctx), error);
+    ctx.pmod = sp;
 
     /* validate non-instantiated groupings from the parsed schema,
      * without it we would accept even the schemas with invalid grouping specification */
-    ctx.pmod = sp;
     ctx.options |= LYS_COMPILE_GROUPING;
     LY_ARRAY_FOR(sp->groupings, u) {
         if (!(sp->groupings[u].flags & LYS_USED_GRP)) {
@@ -1689,6 +1686,9 @@
     }
     ctx.pmod = sp;
 
+    /* finish compilation for all unresolved items in the context */
+    LY_CHECK_GOTO(ret = lys_compile_unres(&ctx), error);
+
     /* there can be no leftover deviations or augments */
     LY_CHECK_ERR_GOTO(ctx.augs.count, LOGINT(ctx.ctx); ret = LY_EINT, error);
     LY_CHECK_ERR_GOTO(ctx.devs.count, LOGINT(ctx.ctx); ret = LY_EINT, error);
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 404150e..d81aa47 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -65,7 +65,7 @@
     struct lysc_unres_dflt *r = NULL;
     uint32_t i;
 
-    if (ctx->options & LYS_COMPILE_DISABLED) {
+    if (ctx->options & (LYS_COMPILE_DISABLED | LYS_COMPILE_GROUPING)) {
         return LY_SUCCESS;
     }
 
@@ -113,7 +113,7 @@
     struct lysc_unres_dflt *r = NULL;
     uint32_t i;
 
-    if (ctx->options & LYS_COMPILE_DISABLED) {
+    if (ctx->options & (LYS_COMPILE_DISABLED | LYS_COMPILE_GROUPING)) {
         return LY_SUCCESS;
     }
 
@@ -2086,7 +2086,7 @@
 
     /* if-features */
     LY_CHECK_RET(lys_eval_iffeatures(ctx->ctx, action_p->iffeatures, &enabled));
-    if (!enabled && !(ctx->options & LYS_COMPILE_DISABLED)) {
+    if (!enabled && !(ctx->options & (LYS_COMPILE_DISABLED | LYS_COMPILE_GROUPING))) {
         ly_set_add(&ctx->disabled, action, 1, NULL);
         ctx->options |= LYS_COMPILE_DISABLED;
     }
@@ -2223,7 +2223,7 @@
 
     /* if-features */
     LY_CHECK_RET(lys_eval_iffeatures(ctx->ctx, notif_p->iffeatures, &enabled));
-    if (!enabled && !(ctx->options & LYS_COMPILE_DISABLED)) {
+    if (!enabled && !(ctx->options & (LYS_COMPILE_DISABLED | LYS_COMPILE_GROUPING))) {
         ly_set_add(&ctx->disabled, notif, 1, NULL);
         ctx->options |= LYS_COMPILE_DISABLED;
     }
@@ -2351,10 +2351,10 @@
         LY_CHECK_RET(lysc_unres_leaf_dflt_add(ctx, leaf, dflt));
     }
 
-    if ((leaf->type->basetype == LY_TYPE_LEAFREF) && !(ctx->options & LYS_COMPILE_DISABLED)) {
+    if ((leaf->type->basetype == LY_TYPE_LEAFREF) && !(ctx->options & (LYS_COMPILE_DISABLED | LYS_COMPILE_GROUPING))) {
         /* store to validate the path in the current context at the end of schema compiling when all the nodes are present */
         LY_CHECK_RET(ly_set_add(&ctx->leafrefs, leaf, 0, NULL));
-    } else if ((leaf->type->basetype == LY_TYPE_UNION) && !(ctx->options & LYS_COMPILE_DISABLED)) {
+    } else if ((leaf->type->basetype == LY_TYPE_UNION) && !(ctx->options & (LYS_COMPILE_DISABLED | LYS_COMPILE_GROUPING))) {
         LY_ARRAY_COUNT_TYPE u;
         LY_ARRAY_FOR(((struct lysc_type_union *)leaf->type)->types, u) {
             if (((struct lysc_type_union *)leaf->type)->types[u]->basetype == LY_TYPE_LEAFREF) {
@@ -3693,7 +3693,7 @@
 
     /* if-features */
     LY_CHECK_ERR_RET(ret = lys_eval_iffeatures(ctx->ctx, pnode->iffeatures, &enabled), free(node), ret);
-    if (!enabled && !(ctx->options & LYS_COMPILE_DISABLED)) {
+    if (!enabled && !(ctx->options & (LYS_COMPILE_DISABLED | LYS_COMPILE_GROUPING))) {
         ly_set_add(&ctx->disabled, node, 1, NULL);
         ctx->options |= LYS_COMPILE_DISABLED;
     }