Fix bug when there are no valid identities

Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/230
Change-Id: I8fa63b8b81b5da3ef7177d470011c168a00c2c5d
diff --git a/src/yang_schema.cpp b/src/yang_schema.cpp
index 266f917..b964d31 100644
--- a/src/yang_schema.cpp
+++ b/src/yang_schema.cpp
@@ -214,8 +214,10 @@
 
     for (auto base : resolveTypedef<ResolveMode::Identity>(type)) { // Iterate over all bases
         // Iterate over derived identities (this is recursive!)
-        for (auto derived : base->der()->schema()) {
-            identSet.emplace(derived->module()->name(), derived->name());
+        if (auto der = base->der()) {
+            for (auto derived : der->schema()) {
+                identSet.emplace(derived->module()->name(), derived->name());
+            }
         }
     }
 
diff --git a/tests/yang.cpp b/tests/yang.cpp
index 85df376..ed4da88 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -59,6 +59,15 @@
 
     include sub-module;
 
+    identity identNoderived {
+    }
+
+    leaf leafNoValidIdent {
+        type identityref {
+            base "identNoderived";
+        }
+    }
+
     identity drink {
     }
 
@@ -782,6 +791,12 @@
                 }};
             }
 
+            SECTION("leafNoValidIdent")
+            {
+                node.first = "example-schema";
+                node.second = "leafNoValidIdent";
+                type = yang::IdentityRef{{}};
+            }
 
             REQUIRE(ys.leafType(path, node) == yang::TypeInfo(type, std::nullopt, expectedDescription));
         }
@@ -830,7 +845,8 @@
                         {"example-schema"s, "addresses"},
                         {"example-schema"s, "subLeaf"},
                         {"example-schema"s, "flagBits"},
-                        {"example-schema"s, "leafFoodTypedef"}};
+                        {"example-schema"s, "leafFoodTypedef"},
+                        {"example-schema"s, "leafNoValidIdent"}};
                 }
 
                 SECTION("example-schema:a")
@@ -898,6 +914,7 @@
                         {"example-schema"s, "leafInt32"},
                         {"example-schema"s, "leafInt64"},
                         {"example-schema"s, "leafInt8"},
+                        {"example-schema"s, "leafNoValidIdent"},
                         {"example-schema"s, "leafString"},
                         {"example-schema"s, "leafUint16"},
                         {"example-schema"s, "leafUint32"},
@@ -965,6 +982,7 @@
                         {boost::none, "/example-schema:leafInt32"},
                         {boost::none, "/example-schema:leafInt64"},
                         {boost::none, "/example-schema:leafInt8"},
+                        {boost::none, "/example-schema:leafNoValidIdent"},
                         {boost::none, "/example-schema:leafString"},
                         {boost::none, "/example-schema:leafUint16"},
                         {boost::none, "/example-schema:leafUint32"},