diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-01-14 17:55:34 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-01-14 17:55:34 +0100 |
commit | f61cca45bd5c57e7a192b48cbeb548224f9c0bb0 (patch) | |
tree | 0dfec5abf093d8ea6fa39644e19c79efab293f48 | |
parent | 34e96b785871497249a705260b8c694f7180a256 (diff) | |
download | vala-f61cca45bd5c57e7a192b48cbeb548224f9c0bb0.tar.gz |
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
-rw-r--r-- | vala/valadatatype.vala | 6 | ||||
-rw-r--r-- | 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; |