diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2023-04-13 20:36:08 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2023-04-14 09:14:11 +0200 |
commit | b42c4b54a3589cffcab9dcce603c82728bcd82d0 (patch) | |
tree | dbd833d214300b7306a57340a180b8c6e2b7d94e /vala | |
parent | cff2e6e470efae1f4e178ab13cb2b3d5dde502c3 (diff) | |
download | vala-b42c4b54a3589cffcab9dcce603c82728bcd82d0.tar.gz |
vala: Don't make GenericType nullable by default
Allow equality between nullable and non-nullable generic-types for now
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1191
Diffstat (limited to 'vala')
-rw-r--r-- | vala/valadatatype.vala | 6 | ||||
-rw-r--r-- | vala/valagenerictype.vala | 7 | ||||
-rw-r--r-- | vala/valamemberaccess.vala | 1 | ||||
-rw-r--r-- | vala/valasymbolresolver.vala | 9 |
4 files changed, 11 insertions, 12 deletions
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index fec7e9010..897eaf72c 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -204,7 +204,11 @@ public abstract class Vala.DataType : CodeNode { return false; } if (type2.nullable != nullable) { - return false; + //TODO Allow equality between nullable and non-nullable generic-types + // This mitigation allows fixing affected source code without breaking it. + // It has to be removed at some point + var context = CodeContext.get (); + return !context.experimental_non_null && this is GenericType == type2 is GenericType; } if (type2.type_symbol != type_symbol) { return false; diff --git a/vala/valagenerictype.vala b/vala/valagenerictype.vala index 32b32ba0e..50c713bce 100644 --- a/vala/valagenerictype.vala +++ b/vala/valagenerictype.vala @@ -40,8 +40,6 @@ public class Vala.GenericType : DataType { public GenericType (TypeParameter type_parameter, SourceReference? source_reference = null) { base.with_symbol (type_parameter, source_reference); - // type parameters are always considered nullable - this.nullable = true; } public override DataType copy () { @@ -62,6 +60,9 @@ public class Vala.GenericType : DataType { } result = SemanticAnalyzer.get_actual_type (derived_instance_type, method_type_arguments, (GenericType) result, node_reference); + if (!result.is_non_null_simple_type ()) { + result.nullable = result.nullable || nullable; + } return result; } @@ -77,7 +78,7 @@ public class Vala.GenericType : DataType { } public override string to_qualified_string (Scope? scope = null) { - return type_parameter.name; + return "%s%s".printf (type_parameter.name, nullable ? "?" : ""); } public override Symbol? get_member (string member_name) { diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala index 2b75adcc5..23078f25b 100644 --- a/vala/valamemberaccess.vala +++ b/vala/valamemberaccess.vala @@ -620,6 +620,7 @@ public class Vala.MemberAccess : Expression { } else if (symbol_reference.error) { //ignore previous error error = true; + value_type = new InvalidType (); return false; } diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index 87352bd00..d029aa9a7 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -473,16 +473,9 @@ public class Vala.SymbolResolver : CodeVisitor { type.source_reference = unresolved_type.source_reference; type.value_owned = unresolved_type.value_owned; + type.nullable = unresolved_type.nullable; sym.used = true; - if (type is GenericType) { - // type parameters are always considered nullable - // actual type argument may or may not be nullable - type.nullable = true; - } else { - type.nullable = unresolved_type.nullable; - } - type.is_dynamic = unresolved_type.is_dynamic; foreach (DataType type_arg in unresolved_type.get_type_arguments ()) { type.add_type_argument (type_arg); |