]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Minor improvement to field getter detection
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 14 Jan 2021 16:55:34 +0000 (17:55 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 14 Jan 2021 16:55:34 +0000 (17:55 +0100)
Allow DataType.compatible() to be called without initialized SemanticAnalyzer

Additionally report a warning if field collides with method

vala/valadatatype.vala
vala/valagirparser.vala

index 04ba297006284ae2c63d03e79c988a53a648e60e..9c5a6846cdc683c5ca3bc25f745ac7cdb4968bb4 100644 (file)
@@ -287,12 +287,14 @@ public abstract class Vala.DataType : CodeNode {
                }
 
                if (context.profile == Profile.GOBJECT && target_type.type_symbol != null) {
-                       if (target_type.type_symbol.is_subtype_of (context.analyzer.gvalue_type.type_symbol)) {
+                       unowned DataType? gvalue_type = context.analyzer.gvalue_type;
+                       if (gvalue_type != null && target_type.type_symbol.is_subtype_of (gvalue_type.type_symbol)) {
                                // allow implicit conversion to GValue
                                return true;
                        }
 
-                       if (target_type.type_symbol.is_subtype_of (context.analyzer.gvariant_type.type_symbol)) {
+                       unowned DataType? gvariant_type = context.analyzer.gvariant_type;
+                       if (gvariant_type != null && target_type.type_symbol.is_subtype_of (gvariant_type.type_symbol)) {
                                // allow implicit conversion to GVariant
                                return true;
                        }
index cdea30f2ad81def1c85159805c7619094f1688d0..c077411cc98d42fb384d829cba6ab96154965201 100644 (file)
@@ -914,9 +914,13 @@ public class Vala.GirParser : CodeVisitor {
                                        var colliding = parent.lookup_all (name);
                                        foreach (var node in colliding) {
                                                var sym = node.symbol;
-                                               if (sym is Field && !(m.return_type is VoidType) && m.get_parameters().size == 0) {
-                                                       // assume method is getter
-                                                       merged = true;
+                                               if (sym is Field) {
+                                                       if (m.return_type.compatible (((Field) sym).variable_type) && m.get_parameters ().size == 0) {
+                                                               // assume method is getter
+                                                               merged = true;
+                                                       } else {
+                                                               Report.warning (symbol.source_reference, "Field `%s' conflicts with method of the same name", get_full_name ());
+                                                       }
                                                } else if (sym is Signal) {
                                                        node.process (parser);
                                                        var sig = (Signal) sym;