printer tree BUGFIX status copy in implicit case

In implicit case, the status is copied from a child.
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index ee44ad5..424b7f8 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -3292,7 +3292,7 @@
     LY_ERR ret = LY_SUCCESS;
     struct lysp_node *child_p_next = child_p->next;
     struct lysp_node_case *cs_p;
-    struct lysc_node *compiled_case;
+    struct lysc_node_case *compiled_case;
 
     if (child_p->nodetype == LYS_CASE) {
         /* standard case under choice */
@@ -3313,15 +3313,24 @@
 free_fake_node:
         /* free the fake parsed node and correct pointers back */
 
-        cs_p->child = NULL;
+        /* get last case node */
+        compiled_case = (struct lysc_node_case *)((struct lysc_node_choice *)node)->cases->prev;
+
         if (ctx->ctx->flags & LY_CTX_SET_PRIV_PARSED) {
-            /* compiled node cannot point to the implicit case node */
-            /* get last case node */
-            compiled_case = ((struct lysc_node_choice *)node)->cases->prev;
+            /* Compiled case node cannot point to his corresponding parsed node
+             * because it exists temporarily. Therefore, it must be set to NULL.
+             */
             assert(compiled_case->priv == cs_p);
-            /* must be set to NULL */
             compiled_case->priv = NULL;
         }
+
+        /* The status is copied from his child and not from his parent as usual. */
+        if (compiled_case->child) {
+            compiled_case->flags &= ~LYS_STATUS_MASK;
+            compiled_case->flags |= LYS_STATUS_MASK & compiled_case->child->flags;
+        }
+
+        cs_p->child = NULL;
         lysp_node_free(ctx->ctx, (struct lysp_node *)cs_p);
         child_p->next = child_p_next;
     }
diff --git a/tests/utests/schema/test_printer_tree.c b/tests/utests/schema/test_printer_tree.c
index eebc8b5..eee35f4 100644
--- a/tests/utests/schema/test_printer_tree.c
+++ b/tests/utests/schema/test_printer_tree.c
@@ -436,6 +436,7 @@
             "  choice shorthand {\n"
             "    container cont1 {\n"
             "      if-feature \"foo\";\n"
+            "      status obsolete;\n"
             "    }\n"
             "    container cont2 {\n"
             "      container cont3;\n"
@@ -459,8 +460,8 @@
             "  +--rw (my_choice)?\n"
             "  |  +--:(my_case)\n"
             "  +--rw (shorthand)?\n"
-            "  |  +--:(cont1)\n"
-            "  |  |  +--rw cont1 {foo}?\n"
+            "  |  o--:(cont1)\n"
+            "  |  |  o--rw cont1 {foo}?\n"
             "  |  +--:(cont2)\n"
             "  |     +--rw cont2\n"
             "  |        +--rw cont3\n"