[gobject-introspection] Add a warning for unresolved types



commit 4577bf1a7f6dc33d1ff566ae8d1360f1fde769f9
Author: Johan Dahlin <johan gnome org>
Date:   Tue Sep 14 23:13:17 2010 -0300

    Add a warning for unresolved types
    
    Warn when using an annotation which will end up as
    unresolved.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=629004

 giscanner/maintransformer.py         |   21 +++++++++++++++------
 tests/warn/Makefile.am               |    1 +
 tests/warn/unresolved-element-type.h |   11 +++++++++++
 3 files changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 130d449..67f6391 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -263,7 +263,7 @@ usage is void (*_gtk_reserved1)(void);"""
                 "Too many parameters in type specification %r" % (type_str, ))
             return base
         def top_combiner(base, *rest):
-            if orig_node is not None:
+            if orig_node is not None and isinstance(orig_node, ast.Type):
                 base.is_const = orig_node.is_const
             return combiner(base, *rest)
 
@@ -271,6 +271,15 @@ usage is void (*_gtk_reserved1)(void);"""
         if rest:
             message.warn("Trailing components in type specification %r" % (
                 type_str, ))
+
+        if not result.resolved:
+            parent = orig_node
+            if isinstance(parent, ast.Function):
+                text = parent.symbol
+            else:
+                text = parent.name
+            message.warn_node(parent, "%s: Unknown type: %r" %
+                              (text, result.ctype))
         return result
 
     def _apply_annotations_array(self, parent, node, options):
@@ -282,7 +291,7 @@ usage is void (*_gtk_reserved1)(void);"""
 
         element_type = options.get(OPT_ELEMENT_TYPE)
         if element_type is not None:
-            element_type_node = self._resolve(element_type.one())
+            element_type_node = self._resolve(element_type.one(), parent)
         elif isinstance(node.type, ast.Array):
             element_type_node = node.type.element_type
         else:
@@ -321,13 +330,13 @@ usage is void (*_gtk_reserved1)(void);"""
         element_type = element_type_opt.flat()
         if isinstance(node.type, ast.List):
             assert len(element_type) == 1
-            node.type.element_type = self._resolve(element_type[0])
+            node.type.element_type = self._resolve(element_type[0], parent)
         elif isinstance(node.type, ast.Map):
             assert len(element_type) == 2
-            node.type.key_type = self._resolve(element_type[0])
-            node.type.value_type = self._resolve(element_type[1])
+            node.type.key_type = self._resolve(element_type[0], parent)
+            node.type.value_type = self._resolve(element_type[1], parent)
         elif isinstance(node.type, ast.Array):
-            node.type.element_type = self._resolve(element_type[0])
+            node.type.element_type = self._resolve(element_type[0], parent)
         else:
             message.warn_node(parent,
                 "Unknown container %r for element-type annotation" % (node.type, ))
diff --git a/tests/warn/Makefile.am b/tests/warn/Makefile.am
index deece2f..921ec59 100644
--- a/tests/warn/Makefile.am
+++ b/tests/warn/Makefile.am
@@ -5,6 +5,7 @@ TESTS = \
 	callback-missing-scope.h \
 	return-gobject.h \
 	unknown-parameter.h \
+	unresolved-element-type.h \
 	unresolved-type.h
 
 EXTRA_DIST = warningtester.py common.h $(TESTS)
diff --git a/tests/warn/unresolved-element-type.h b/tests/warn/unresolved-element-type.h
new file mode 100644
index 0000000..af60a39
--- /dev/null
+++ b/tests/warn/unresolved-element-type.h
@@ -0,0 +1,11 @@
+#include "common.h"
+
+/**
+ * test_unresolved_element_type:
+ *
+ * Returns: (element-type Unresolved) (transfer full):
+ */
+
+GList* test_unresolved_element_type(void);
+
+// EXPECT:9: Warning: Test: test_unresolved_element_type: Unknown type: 'Unresolved'



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]