From 54778adf82fe55fa0adefeb8f0322c6696a104ba Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 14 Sep 2019 11:14:50 +0200 Subject: [PATCH] Allow variables be assigned to other types if they are implicitly castable --- src/Binder/BoundVariables/BoundScope.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Binder/BoundVariables/BoundScope.cpp b/src/Binder/BoundVariables/BoundScope.cpp index b52dc77..93f0fd8 100644 --- a/src/Binder/BoundVariables/BoundScope.cpp +++ b/src/Binder/BoundVariables/BoundScope.cpp @@ -101,8 +101,12 @@ namespace Porygon::Binder { } else { // Assigning auto var = this->GetVariable(exists, identifier); - if (var->GetType()->operator!=(type)) { - return VariableAssignment(VariableAssignmentResult::VariableDefinedWithDifferentType, nullptr); + auto t= var->GetType(); + if (t->operator!=(type)) { + auto castResult = type->CastableTo(t, false); + if (castResult == CastResult::InvalidCast){ + return VariableAssignment(VariableAssignmentResult::VariableDefinedWithDifferentType, nullptr); + } } return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, exists, false, type)); }