Commits

Jan Borsodi committed c8c96b5

Fixed parsing of default values for enum fields when numbers are used, now it searches for an enum entry with the same number.

Comments (0)

Files changed (2)

         if isinstance(self._item, Field) and self._item.message:
             def set_default_enum(sym, item):
                 if isinstance(sym.owner.message, Enum):
+                    # Compatibility with code that expects a number in item.default
+                    if isinstance(item, EnumValue):
+                        sym.owner.setDefaultValue(item.value)
+                        sym.owner.setDefaultText(str(item.value))
                     sym.owner.setDefaultObject(item)
                 else:
                     raise BuildError("Messages can't have default values")
         if current:
             while current:
                 for child in current.items:
-                    if child.name == path[0]:
+                    num = None
+                    if isinstance(child, EnumValue):
+                        try:
+                            num = int(path[0])
+                        except ValueError:
+                            pass
+                    if child.name == path[0] or (num is not None and child.value == num):
                         item = child
                         if path[1:]:
                             item = msg_find(item, path[1:])
         self.default = value
         self.default_object = value
 
+    def setDefaultValue(self, value):
+        self.default = value
+
     def setDefaultText(self, text):
         self.default_text = text