schema compile UPDATE use compiled module as current mod for unique

It is not clear when should what module be used in
the YANG 1.1 specs so just use what is most natural
and expected.

Fixes #1751
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index c3251b1..d39c37f 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -2966,7 +2966,6 @@
  * @param[in] nodeid Descendant-schema-nodeid (according to the YANG grammar)
  * @param[in] nodeid_len Length of the given nodeid, if it is not NULL-terminated string.
  * @param[in] ctx_node Context node for a relative nodeid.
- * @param[in] cur_mod Current module for the nodeid (where it was "instantiated").
  * @param[in] format Format of any prefixes.
  * @param[in] prefix_data Format-specific prefix data (see ::ly_resolve_prefix).
  * @param[in] nodetype Optional (can be 0) restriction for target's nodetype. If target exists, but does not match
@@ -2979,8 +2978,7 @@
  */
 static LY_ERR
 lysc_resolve_schema_nodeid(struct lysc_ctx *ctx, const char *nodeid, size_t nodeid_len, const struct lysc_node *ctx_node,
-        const struct lys_module *cur_mod, LY_VALUE_FORMAT format, void *prefix_data, uint16_t nodetype,
-        const struct lysc_node **target, uint16_t *result_flag)
+        LY_VALUE_FORMAT format, void *prefix_data, uint16_t nodetype, const struct lysc_node **target, uint16_t *result_flag)
 {
     LY_ERR ret = LY_EVALID;
     const char *name, *prefix, *id;
@@ -3037,7 +3035,7 @@
             case LY_VALUE_SCHEMA:
             case LY_VALUE_SCHEMA_RESOLVED:
                 /* use the current module */
-                mod = cur_mod;
+                mod = ctx->cur_mod;
                 break;
             case LY_VALUE_JSON:
             case LY_VALUE_LYB:
@@ -3152,8 +3150,8 @@
 
             /* unique node must be present */
             LY_ARRAY_NEW_RET(ctx->ctx, *unique, key, LY_EMEM);
-            ret = lysc_resolve_schema_nodeid(ctx, keystr, len, &list->node, uniques[v].mod->mod,
-                    LY_VALUE_SCHEMA, (void *)uniques[v].mod, LYS_LEAF, (const struct lysc_node **)key, &flags);
+            ret = lysc_resolve_schema_nodeid(ctx, keystr, len, &list->node, LY_VALUE_SCHEMA, (void *)uniques[v].mod,
+                    LYS_LEAF, (const struct lysc_node **)key, &flags);
             if (ret != LY_SUCCESS) {
                 if (ret == LY_EDENIED) {
                     LOGVAL(ctx->ctx, LYVE_REFERENCE,
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 7f08c3b..77bf19c 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -2465,6 +2465,12 @@
     assert_non_null(child = lysc_node_child(child));
     assert_string_equal("x", child->name);
 
+    /* unique */
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module j {namespace urn:j;prefix j;"
+            "grouping grp {list l {key \"k\"; unique \"l\"; leaf k {type string;} leaf l {type string;}}}}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k;import j {prefix j;}"
+            "container a {uses j:grp;}}", LYS_IN_YANG, NULL));
+
     /* invalid */
     assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;uses missinggrp;}", LYS_IN_YANG, &mod));
     CHECK_LOG_CTX("Grouping \"missinggrp\" referenced by a uses statement not found.", "/aa:{uses='missinggrp'}");
@@ -3007,7 +3013,7 @@
             "         leaf c {type string;} leaf d {type string;}}}");
     assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;import i {prefix i;}"
             "augment /i:l1 {leaf j_c {type string;}}"
-            "deviation /i:l1 {deviate add {unique \"i:b j_c\"; }}"
+            "deviation /i:l1 {deviate add {unique \"b j:j_c\"; }}"
             "deviation /i:l1 {deviate add {unique \"i:c\";}}"
             "deviation /i:l2 {deviate delete {unique \"d\"; unique \"b c\";}}}", LYS_IN_YANG, NULL));
     assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "i")));