[vala/staging] vala: Silently accept unsafe assignment of "0" literal to enum type



commit 4c2768496938ec2d9c82377a138efd2cc42bbafe
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Dec 17 11:43:33 2021 +0100

    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 ());
                        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]