From 4c2768496938ec2d9c82377a138efd2cc42bbafe Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Fri, 17 Dec 2021 11:43:33 +0100 Subject: [PATCH] vala: Silently accept unsafe assignment of "0" literal to enum type In addition to 9f1de7ae875b59939ca6200e08dddd69106fb486 --- vala/valaassignment.vala | 3 ++- vala/valalocalvariable.vala | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) 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 ()); } -- 2.47.2