[vala/staging] girparser: Minor improvement to field getter detection



commit f61cca45bd5c57e7a192b48cbeb548224f9c0bb0
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Jan 14 17:55:34 2021 +0100

    girparser: Minor improvement to field getter detection
    
    Allow DataType.compatible() to be called without initialized SemanticAnalyzer
    
    Additionally report a warning if field collides with method

 vala/valadatatype.vala  |  6 ++++--
 vala/valagirparser.vala | 10 +++++++---
 2 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 04ba29700..9c5a6846c 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -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;
                        }
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index cdea30f2a..c077411cc 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -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;


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