schema features BUGFIX postpone feature check until compilation

Otherwise it is not possible to enable features
dependent on features in other modules.

Fixes #1785
diff --git a/src/schema_compile.c b/src/schema_compile.c
index faa487d..aeeb239 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -1605,12 +1605,39 @@
     return ret;
 }
 
+/**
+ * @brief Check if-feature of all features of all modules in a dep set.
+ *
+ * @param[in] dep_set Dep set to check.
+ * @return LY_ERR value.
+ */
+static LY_ERR
+lys_compile_depset_check_features(struct ly_set *dep_set)
+{
+    struct lys_module *mod;
+    uint32_t i;
+
+    for (i = 0; i < dep_set->count; ++i) {
+        mod = dep_set->objs[i];
+        if (!mod->to_compile) {
+            /* skip */
+            continue;
+        }
+
+        /* check features of this module */
+        LY_CHECK_RET(lys_check_features(mod->parsed));
+    }
+
+    return LY_SUCCESS;
+}
+
 LY_ERR
 lys_compile_depset_all(struct ly_ctx *ctx, struct lys_glob_unres *unres)
 {
     uint32_t i;
 
     for (i = 0; i < unres->dep_sets.count; ++i) {
+        LY_CHECK_RET(lys_compile_depset_check_features(unres->dep_sets.objs[i]));
         LY_CHECK_RET(lys_compile_depset_r(ctx, unres->dep_sets.objs[i], unres));
     }
 
diff --git a/src/schema_features.c b/src/schema_features.c
index 2189046..fc6843a 100644
--- a/src/schema_features.c
+++ b/src/schema_features.c
@@ -386,7 +386,8 @@
     }
     if (j) {
         /* not matching count of ( and ) */
-        LOGVAL(ctx, LYVE_SYNTAX_YANG, "Invalid value \"%s\" of if-feature - non-matching opening and closing parentheses.", qname->str);
+        LOGVAL(ctx, LYVE_SYNTAX_YANG, "Invalid value \"%s\" of if-feature - non-matching opening and closing parentheses.",
+                qname->str);
         return LY_EVALID;
     }
     if (f_exp != f_size) {
@@ -399,7 +400,8 @@
     if (checkversion || (expr_size > 1)) {
         /* check that we have 1.1 module */
         if (qname->mod->version != LYS_VERSION_1_1) {
-            LOGVAL(ctx, LYVE_SYNTAX_YANG, "Invalid value \"%s\" of if-feature - YANG 1.1 expression in YANG 1.0 module.", qname->str);
+            LOGVAL(ctx, LYVE_SYNTAX_YANG, "Invalid value \"%s\" of if-feature - YANG 1.1 expression in YANG 1.0 module.",
+                    qname->str);
             return LY_EVALID;
         }
     }
@@ -529,15 +531,8 @@
     return LY_SUCCESS;
 }
 
-/**
- * @brief Check whether all enabled features have their if-features satisfied.
- * Enabled features with false if-features are disabled with a warning.
- *
- * @param[in] pmod Parsed module features to check.
- * @return LY_ERR value.
- */
-static LY_ERR
-lys_check_features(struct lysp_module *pmod)
+LY_ERR
+lys_check_features(const struct lysp_module *pmod)
 {
     LY_ERR r;
     uint32_t i = 0;
@@ -552,12 +547,9 @@
         assert(f->iffeatures_c);
         r = lysc_iffeature_value(f->iffeatures_c);
         if (r == LY_ENOT) {
-            LOGWRN(pmod->mod->ctx, "Feature \"%s\" cannot be enabled because its \"if-feature\" is not satisfied.",
+            LOGERR(pmod->mod->ctx, LY_EDENIED, "Feature \"%s\" cannot be enabled because its \"if-feature\" is not satisfied.",
                     f->name);
-
-            /* disable feature and re-evaluate all the feature if-features again */
-            f->flags &= ~LYS_FENABLED;
-            return lys_check_features(pmod);
+            return LY_EDENIED;
         } else if (r) {
             return r;
         } /* else if-feature satisfied */
@@ -626,8 +618,7 @@
         return LY_EEXIST;
     }
 
-    /* check final features if-feature state */
-    return lys_check_features(pmod);
+    return LY_SUCCESS;
 }
 
 /**
diff --git a/src/schema_features.h b/src/schema_features.h
index 2e4a085..f12dc54 100644
--- a/src/schema_features.h
+++ b/src/schema_features.h
@@ -33,7 +33,17 @@
 LY_ERR lys_eval_iffeatures(const struct ly_ctx *ctx, struct lysp_qname *iffeatures, ly_bool *enabled);
 
 /**
- * @brief Set the specified features of a parsed module, with all the checks.
+ * @brief Check whether all enabled features have their if-features satisfied.
+ *
+ * @param[in] pmod Parsed module features to check.
+ * @return LY_SUCCESS on success.
+ * @return LY_EDENIED if there was an enabled feature with disabled if-feature.
+ */
+LY_ERR lys_check_features(const struct lysp_module *pmod);
+
+/**
+ * @brief Set the specified features of a parsed module ignoring their own if-features. These are all checked before
+ * compiling the module(s).
  *
  * @param[in] pmod Parsed module to modify.
  * @param[in] features Array of features ended with NULL to be enabled if the module is being implemented.