tree schema UPDATE store typedef name in the compiled type
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 2bb7af3..d0b3431 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -1675,29 +1675,35 @@
 /**
  * @brief Allocate a new specific type structure according to the basetype.
  *
+ * @param[in] ctx Context to use.
  * @param[in] basetype Base type of the new type.
- * @return Specific type structure.
+ * @param[in] tpdf_name Optional referenced typedef name, NULL for built-in types.
+ * @param[out] type Specific type structure.
+ * @return LY_ERR value.
  */
-static struct lysc_type *
-lys_new_type(LY_DATA_TYPE basetype)
+static LY_ERR
+lys_new_type(const struct ly_ctx *ctx, LY_DATA_TYPE basetype, const char *tpdf_name, struct lysc_type **type)
 {
-    struct lysc_type *type = NULL;
+    LY_ERR rc = LY_SUCCESS;
+    struct lysc_type *t = NULL;
+
+    *type = NULL;
 
     switch (basetype) {
     case LY_TYPE_BINARY:
-        type = calloc(1, sizeof(struct lysc_type_bin));
+        t = calloc(1, sizeof(struct lysc_type_bin));
         break;
     case LY_TYPE_BITS:
-        type = calloc(1, sizeof(struct lysc_type_bits));
+        t = calloc(1, sizeof(struct lysc_type_bits));
         break;
     case LY_TYPE_DEC64:
-        type = calloc(1, sizeof(struct lysc_type_dec));
+        t = calloc(1, sizeof(struct lysc_type_dec));
         break;
     case LY_TYPE_STRING:
-        type = calloc(1, sizeof(struct lysc_type_str));
+        t = calloc(1, sizeof(struct lysc_type_str));
         break;
     case LY_TYPE_ENUM:
-        type = calloc(1, sizeof(struct lysc_type_enum));
+        t = calloc(1, sizeof(struct lysc_type_enum));
         break;
     case LY_TYPE_INT8:
     case LY_TYPE_UINT8:
@@ -1707,29 +1713,41 @@
     case LY_TYPE_UINT32:
     case LY_TYPE_INT64:
     case LY_TYPE_UINT64:
-        type = calloc(1, sizeof(struct lysc_type_num));
+        t = calloc(1, sizeof(struct lysc_type_num));
         break;
     case LY_TYPE_IDENT:
-        type = calloc(1, sizeof(struct lysc_type_identityref));
+        t = calloc(1, sizeof(struct lysc_type_identityref));
         break;
     case LY_TYPE_LEAFREF:
-        type = calloc(1, sizeof(struct lysc_type_leafref));
+        t = calloc(1, sizeof(struct lysc_type_leafref));
         break;
     case LY_TYPE_INST:
-        type = calloc(1, sizeof(struct lysc_type_instanceid));
+        t = calloc(1, sizeof(struct lysc_type_instanceid));
         break;
     case LY_TYPE_UNION:
-        type = calloc(1, sizeof(struct lysc_type_union));
+        t = calloc(1, sizeof(struct lysc_type_union));
         break;
     case LY_TYPE_BOOL:
     case LY_TYPE_EMPTY:
-        type = calloc(1, sizeof(struct lysc_type));
+        t = calloc(1, sizeof(struct lysc_type));
         break;
     case LY_TYPE_UNKNOWN:
         break;
     }
+    LY_CHECK_ERR_GOTO(!t, LOGMEM(ctx); rc = LY_EMEM, cleanup);
 
-    return type;
+    if (tpdf_name) {
+        rc = lydict_insert(ctx, tpdf_name, 0, &t->name);
+        LY_CHECK_GOTO(rc, cleanup);
+    }
+
+cleanup:
+    if (rc) {
+        free(t);
+    } else {
+        *type = t;
+    }
+    return rc;
 }
 
 /**
@@ -1737,7 +1755,8 @@
  *
  * @param[in] ctx Compile context.
  * @param[in] context_pnode Schema node where the type/typedef is placed to correctly find the base types.
- * @param[in] context_flags Flags of the context node or the referencing typedef to correctly check status of referencing and referenced objects.
+ * @param[in] context_flags Flags of the context node or the referencing typedef to correctly check status of
+ * referencing and referenced objects.
  * @param[in] context_name Name of the context node or referencing typedef for logging.
  * @param[in] type_p Parsed type to compile.
  * @param[in] basetype Base YANG built-in type of the type to compile.
@@ -1769,8 +1788,8 @@
     uint32_t i;
 
     /* alloc and init */
-    *type = lys_new_type(basetype);
-    LY_CHECK_ERR_GOTO(!(*type), LOGMEM(ctx->ctx), cleanup);
+    rc = lys_new_type(ctx->ctx, basetype, tpdfname, type);
+    LY_CHECK_GOTO(rc, cleanup);
 
     (*type)->basetype = basetype;
     (*type)->plugin = plugin;