Allow variables be assigned to other types if they are implicitly castable
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-09-14 11:14:50 +02:00
parent 9520b98f2e
commit 54778adf82
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 6 additions and 2 deletions

View File

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