Allow DataType.compatible() to be called without initialized SemanticAnalyzer
Additionally report a warning if field collides with method
}
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;
}
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;