[gobject-introspection/ebassi/signal-emitter: 15/15] scanner: Validate emitter methods




commit a8453f0e9109dde7dc980b245e57191622432bbc
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Jun 24 18:00:02 2021 +0100

    scanner: Validate emitter methods
    
    Follow the same semantics as Vala:
    
     1. emitters should have the same return value as the signal
     2. emitters should have the same parameters as the signal they
        emit (minus the instance parameter, which is implied in
        signals)

 giscanner/introspectablepass.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
---
diff --git a/giscanner/introspectablepass.py b/giscanner/introspectablepass.py
index e2056b42..81c8e429 100644
--- a/giscanner/introspectablepass.py
+++ b/giscanner/introspectablepass.py
@@ -207,6 +207,41 @@ class IntrospectablePass(object):
             if not self._type_is_introspectable(obj.retval.type):
                 obj.introspectable = False
                 return True
+        if isinstance(obj, ast.Signal):
+            if obj.emitter is None:
+                return False
+            parent = stack[0]
+            for method in parent.methods:
+                if method.name != obj.emitter:
+                    continue
+                if not obj.retval.type.is_equiv(method.retval.type):
+                    self._parameter_warning(
+                        parent,
+                        obj,
+                        "Emitter method %s for signal %s::%s does not have the "
+                        "same return value type" % (method.symbol, parent.name, obj.name))
+                    obj.emitter = None
+                    return False
+                n_emitter_params = len(method.parameters)
+                n_signal_params = len(obj.parameters)
+                if n_emitter_params != n_signal_params:
+                    self._parameter_warning(
+                        parent,
+                        obj,
+                        "Emitter method %s for signal %s::%s does not have the "
+                        "same number of arguments (expected: %d)" % (method.symbol, parent.name, obj.name, 
n_signal_params))
+                    obj.emitter = None
+                    return False
+                for idx, signal_param in enumerate(obj.parameters):
+                    method_param = method.parameters[idx + 1]
+                    if signal_param.type.is_equiv(method_param.type):
+                        self._parameter_warning(
+                            parent,
+                            obj,
+                            "Emitter method %s for signal %s::%s does not have the "
+                            "same type of arguments" % (method.symbol, parent.name, obj.name))
+                        obj.emitter = None
+                        return False
         return True
 
     def _introspectable_pass3(self, obj, stack):


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