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());
|
: this->_scope->AssignVariable(s->GetIdentifier(), boundExpression->GetType());
|
||||||
if (assignment.GetResult() == VariableAssignmentResult::Ok) {
|
if (assignment.GetResult() == VariableAssignmentResult::Ok) {
|
||||||
auto key = assignment.GetKey();
|
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);
|
return new BoundAssignmentStatement(key, boundExpression);
|
||||||
} else {
|
} else {
|
||||||
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantAssignVariable,
|
this->_scriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::CantAssignVariable,
|
||||||
|
|
|
@ -107,6 +107,7 @@ namespace Porygon::Binder {
|
||||||
if (castResult == CastResult::InvalidCast){
|
if (castResult == CastResult::InvalidCast){
|
||||||
return VariableAssignment(VariableAssignmentResult::VariableDefinedWithDifferentType, nullptr);
|
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));
|
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 {
|
EvalValue *NumericEvalValue::Cast(shared_ptr<const ScriptType> castType) const {
|
||||||
if (castType->GetClass() == TypeClass::Number){
|
if (castType->GetClass() == TypeClass::Number){
|
||||||
auto num = static_pointer_cast<const NumericScriptType>(castType);
|
auto num = static_pointer_cast<const NumericScriptType>(castType);
|
||||||
if (num->IsFloat()){
|
if (num->IsFloat() && !this->_isFloat){
|
||||||
return new NumericEvalValue(std::get<int64_t >(_intValue));
|
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);
|
return EvalValue::Cast(castType);
|
||||||
|
|
Loading…
Reference in New Issue