Fixes for implicit casting when assigning variables
This commit is contained in:
parent
54778adf82
commit
98b605a18b
|
@ -85,6 +85,10 @@ namespace Porygon::Binder {
|
|||
: this->_scope->AssignVariable(s->GetIdentifier(), boundExpression->GetType());
|
||||
if (assignment.GetResult() == VariableAssignmentResult::Ok) {
|
||||
auto key = assignment.GetKey();
|
||||
auto type = assignment.GetKey()->GetType();
|
||||
if (type != nullptr && type->operator!=(boundExpression->GetType())){
|
||||
boundExpression = new BoundCastExpression(boundExpression, type);
|
||||
}
|
||||
return new BoundAssignmentStatement(key, boundExpression);
|
||||
} else {
|
||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantAssignVariable,
|
||||
|
|
|
@ -107,6 +107,7 @@ namespace Porygon::Binder {
|
|||
if (castResult == CastResult::InvalidCast){
|
||||
return VariableAssignment(VariableAssignmentResult::VariableDefinedWithDifferentType, nullptr);
|
||||
}
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, exists, false, t));
|
||||
}
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, exists, false, type));
|
||||
}
|
||||
|
|
|
@ -82,8 +82,11 @@ namespace Porygon::Evaluation {
|
|||
EvalValue *NumericEvalValue::Cast(shared_ptr<const ScriptType> castType) const {
|
||||
if (castType->GetClass() == TypeClass::Number){
|
||||
auto num = static_pointer_cast<const NumericScriptType>(castType);
|
||||
if (num->IsFloat()){
|
||||
return new NumericEvalValue(std::get<int64_t >(_intValue));
|
||||
if (num->IsFloat() && !this->_isFloat){
|
||||
return new NumericEvalValue(static_cast<double>(std::get<int64_t >(_intValue)));
|
||||
}
|
||||
else if(!num->IsFloat() && this->_isFloat){
|
||||
return new NumericEvalValue(static_cast<int64_t>(std::get<double >(_floatValue)));
|
||||
}
|
||||
}
|
||||
return EvalValue::Cast(castType);
|
||||
|
|
Loading…
Reference in New Issue