diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index a69e12a..03df6dc 100644
--- a/codegen/valagirwriter.vala
+++ b/codegen/valagirwriter.vala
@@ -1414,7 +1414,11 @@ public class Vala.GIRWriter : CodeVisitor {
 					if (!externals.contains (external)) {
 						externals.add (external);
 					}
-					var type_name = type_symbol.get_attribute_string ("GIR", "name") ?? type_symbol.name;
+					var type_name = type_symbol.get_attribute_string ("GIR", "name");
+					if(type_name == null) {
+						var segments = type_symbol.get_full_name().split(".");
+						type_name = string.joinv("",segments[1:segments.length]);
+					}
 					return "%s.%s".printf (type_symbol.source_reference.file.gir_namespace, type_name);
 				} else {
 					unannotated_namespaces.add(ns);
