From: Rico Tzschichholz Date: Fri, 17 Dec 2021 10:43:33 +0000 (+0100) Subject: vala: Silently accept unsafe assignment of "0" literal to enum type X-Git-Tag: 0.55.1~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c2768496938ec2d9c82377a138efd2cc42bbafe;p=thirdparty%2Fvala.git vala: Silently accept unsafe assignment of "0" literal to enum type In addition to 9f1de7ae875b59939ca6200e08dddd69106fb486 --- diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala index fdec022b6..8c0948ef3 100644 --- a/vala/valaassignment.vala +++ b/vala/valaassignment.vala @@ -320,7 +320,8 @@ public class Vala.Assignment : Expression { error = true; Report.error (source_reference, "Assignment: Cannot convert from `%s' to `%s'", right.value_type.to_string (), left.value_type.to_string ()); return false; - } else if (left.value_type is EnumValueType && right.value_type is IntegerType) { + } else if (left.value_type is EnumValueType && right.value_type is IntegerType + && (!(right is IntegerLiteral) || ((IntegerLiteral) right).value != "0")) { //FIXME This will have to be an error in the future? Report.notice (source_reference, "Assignment: Unsafe conversion from `%s' to `%s'", right.value_type.to_string (), left.value_type.to_string ()); } diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala index 5988085c7..e2a5c92c2 100644 --- a/vala/valalocalvariable.vala +++ b/vala/valalocalvariable.vala @@ -219,7 +219,8 @@ public class Vala.LocalVariable : Variable { error = true; Report.error (source_reference, "Assignment: Cannot convert from `%s' to `%s'", initializer.value_type.to_string (), variable_type.to_string ()); return false; - } else if (variable_type is EnumValueType && initializer.value_type is IntegerType) { + } else if (variable_type is EnumValueType && initializer.value_type is IntegerType + && (!(initializer is IntegerLiteral) || ((IntegerLiteral) initializer).value != "0")) { //FIXME This will have to be an error in the future? Report.notice (source_reference, "Assignment: Unsafe conversion from `%s' to `%s'", initializer.value_type.to_string (), variable_type.to_string ()); }