schema compile BUGFIX prevent when unres without a node
diff --git a/src/schema_compile.c b/src/schema_compile.c
index 83851bf..2aecc02 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -1299,11 +1299,9 @@
         w = ds_unres->whens.objs[i];
         LYSC_CTX_INIT_PMOD(cctx, w->node->module->parsed, NULL);
 
-        if (w->node) {
-            LOG_LOCSET(w->node, NULL);
-        }
+        LOG_LOCSET(w->node, NULL);
         ret = lys_compile_unres_when(&cctx, w->when, w->node);
-        LOG_LOCBACK(w->node ? 1 : 0, 0);
+        LOG_LOCBACK(1, 0);
         LY_CHECK_GOTO(ret, cleanup);
 
         free(w);
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 560756a..c7724ec 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -548,8 +548,10 @@
         *new_when = *when_c;
     }
 
-    /* add when to unres */
-    LY_CHECK_GOTO(rc = lysc_unres_when_add(ctx, *new_when, node), cleanup);
+    if (node) {
+        /* add when to unres if there is a node for evaluation (not for extension instances) */
+        LY_CHECK_GOTO(rc = lysc_unres_when_add(ctx, *new_when, node), cleanup);
+    }
 
 cleanup:
     return rc;