schema compile CHANGE make leafref targets implemented

When leafref path touches nodes from the modules which are not
implemented, make such modules implemented (similarly as augments do).
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index 612b183..73cecc9 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -2295,8 +2295,6 @@
     assert(startnode);
     assert(leafref);
 
-    /* TODO leafref targets may be not implemented, in such a case we actually could make (we did it in libyang1) such a models implemented */
-
     iter = 0;
     id = leafref->path;
     while(*id && (ret = lys_path_token(&id, &prefix, &prefix_len, &name, &name_len, &parent_times, &has_predicate)) == LY_SUCCESS) {
@@ -2324,6 +2322,10 @@
                    id - leafref->path, leafref->path);
             return LY_EVALID;
         }
+        if (!mod->implemented) {
+            /* make the module implemented */
+            ly_ctx_module_implement_internal(ctx->ctx, (struct lys_module*)mod, 2);
+        }
 
         node = lys_child(parent, mod, name, name_len, 0, LYS_GETNEXT_NOSTATECHECK);
         if (!node) {