summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2021-06-13 14:01:55 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2021-08-05 18:09:06 +0100
commit3c186899ece953ba7f8b310f94e57c699554baa8 (patch)
tree6d2b2bee44e3664eef57e584337001a4422df864
parente79ea48ac3fa5db8a3042b7ff2bc0c3976833f51 (diff)
downloadgobject-introspection-3c186899ece953ba7f8b310f94e57c699554baa8.tar.gz
Handle property name collisions
Properties cannot have the same name as signals, methods, and virtual functions, as they will break various language bindings. Since listing this requirement only in the documentation has been insufficient, we should emit a warning, and hope that library developers will pay attention to it. Fixes: #386
-rw-r--r--giscanner/introspectablepass.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/giscanner/introspectablepass.py b/giscanner/introspectablepass.py
index 305e192e..9681d9b7 100644
--- a/giscanner/introspectablepass.py
+++ b/giscanner/introspectablepass.py
@@ -40,6 +40,7 @@ class IntrospectablePass(object):
self._namespace.walk(self._introspectable_property_analysis)
self._namespace.walk(self._introspectable_pass3)
self._namespace.walk(self._remove_non_reachable_backcompat_copies)
+ self._namespace.walk(self._introspectable_symbol_collisions)
def _parameter_warning(self, parent, param, text, position=None):
# Suppress VFunctions and Callbacks warnings for now
@@ -260,3 +261,43 @@ class IntrospectablePass(object):
if not obj.introspectable:
obj.internal_skipped = True
return True
+
+ def _property_warning(self, parent, prop, text, position=None):
+ context = "property %s:%s: " % (parent.name, prop.name, )
+ message.warn_node(parent, context + text, positions=position)
+
+ def _property_signal_collision(self, obj, prop):
+ for s in obj.signals:
+ if s.skip or not s.introspectable:
+ continue
+ if s.name.replace('-', '_') == prop.name.replace('-', '_'):
+ self._property_warning(obj, prop, "Properties cannot have the same name as signals")
+ return False
+
+ def _property_method_collision(self, obj, prop):
+ for m in obj.methods:
+ if m.skip or not m.introspectable:
+ continue
+ if m.name == prop.name.replace('-', '_'):
+ self._property_warning(obj, prop, "Properties cannot have the same name as methods")
+ return False
+
+ def _property_vfunc_collision(self, obj, prop):
+ for vfunc in obj.virtual_methods:
+ if vfunc.skip or not vfunc.introspectable:
+ continue
+ if vfunc.name == prop.name.replace('-', '_'):
+ self._property_warning(obj, prop, "Properties cannot have the same name as virtual methods")
+ return False
+
+ def _introspectable_symbol_collisions(self, obj, stack):
+ if obj.skip:
+ return False
+ if isinstance(obj, (ast.Class, ast.Interface)):
+ for prop in obj.properties:
+ if prop.skip or not prop.introspectable:
+ continue
+ self._property_signal_collision(obj, prop)
+ self._property_method_collision(obj, prop)
+ self._property_vfunc_collision(obj, prop)
+ return True