validation BUGFIX proper accessible tree for dummy when

Fixes #1840
diff --git a/src/validation.c b/src/validation.c
index bf185f0..e26f7a5 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -710,6 +710,7 @@
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyd_node *tree, *dummy = NULL;
+    uint32_t xp_opts;
 
     /* find root */
     if (parent) {
@@ -737,8 +738,15 @@
         }
     }
 
+    /* explicitly specified accesible tree */
+    if (snode->flags & LYS_CONFIG_W) {
+        xp_opts = LYXP_ACCESS_TREE_CONFIG;
+    } else {
+        xp_opts = LYXP_ACCESS_TREE_ALL;
+    }
+
     /* evaluate all when */
-    ret = lyd_validate_node_when(tree, dummy, snode, 0, disabled);
+    ret = lyd_validate_node_when(tree, dummy, snode, xp_opts, disabled);
     if (ret == LY_EINCOMPLETE) {
         /* all other when must be resolved by now */
         LOGINT(snode->module->ctx);
diff --git a/src/xpath.c b/src/xpath.c
index e45b489..37d1021 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -8679,6 +8679,13 @@
 {
     const struct lysc_node *op;
 
+    /* explicit */
+    if (options & LYXP_ACCESS_TREE_ALL) {
+        return LYXP_NODE_ROOT;
+    } else if (options & LYXP_ACCESS_TREE_CONFIG) {
+        return LYXP_NODE_ROOT_CONFIG;
+    }
+
     if (options & LYXP_SCNODE_ALL) {
         /* schema */
         for (op = ctx_scnode; op && !(op->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)); op = op->parent) {}
diff --git a/src/xpath.h b/src/xpath.h
index e24f157..2d09887 100644
--- a/src/xpath.h
+++ b/src/xpath.h
@@ -341,15 +341,17 @@
         uint32_t options);
 
 /** used only internally, maps with @ref findxpathoptions */
-#define LYXP_IGNORE_WHEN    0x01    /**< Ignore unevaluated when in data nodes and do not return ::LY_EINCOMPLETE. */
-#define LYXP_SCHEMA         0x02    /**< Apply data node access restrictions defined for 'when' and 'must' evaluation. */
-#define LYXP_SCNODE         0x04    /**< No special tree access modifiers. */
-#define LYXP_SCNODE_SCHEMA  LYS_FIND_XP_SCHEMA  /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
-#define LYXP_SCNODE_OUTPUT  LYS_FIND_XP_OUTPUT  /**< Search RPC/action output nodes instead of input ones. */
-#define LYXP_SCNODE_ALL     0x1C    /**< mask for all the LYXP_* values */
-#define LYXP_SKIP_EXPR      0x20    /**< The rest of the expression will not be evaluated (lazy evaluation) */
-#define LYXP_SCNODE_ERROR   LYS_FIND_NO_MATCH_ERROR /**< Return error if a path segment matches no nodes, otherwise only
-                                                         warning is printed. */
+#define LYXP_IGNORE_WHEN     0x01   /**< Ignore unevaluated when in data nodes and do not return ::LY_EINCOMPLETE. */
+#define LYXP_SCHEMA          0x02   /**< Apply data node access restrictions defined for 'when' and 'must' evaluation. */
+#define LYXP_SCNODE          0x04   /**< No special tree access modifiers. */
+#define LYXP_SCNODE_SCHEMA   LYS_FIND_XP_SCHEMA /**< Apply node access restrictions defined for 'when' and 'must' evaluation. */
+#define LYXP_SCNODE_OUTPUT   LYS_FIND_XP_OUTPUT /**< Search RPC/action output nodes instead of input ones. */
+#define LYXP_SCNODE_ALL      0x1C   /**< mask for all the LYXP_* values */
+#define LYXP_SKIP_EXPR       0x20   /**< The rest of the expression will not be evaluated (lazy evaluation) */
+#define LYXP_SCNODE_ERROR    LYS_FIND_NO_MATCH_ERROR    /**< Return error if a path segment matches no nodes, otherwise only
+                                                             warning is printed. */
+#define LYXP_ACCESS_TREE_ALL 0x80   /**< Explicit accessible tree of all the nodes. */
+#define LYXP_ACCESS_TREE_CONFIG 0x0100  /**< Explicit accessible tree of only configuration data. */
 
 /**
  * @brief Cast XPath set to another type.