diff --git a/src/Binder/Binder.cpp b/src/Binder/Binder.cpp index c770c5b..7672cb0 100644 --- a/src/Binder/Binder.cpp +++ b/src/Binder/Binder.cpp @@ -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, diff --git a/src/Binder/BoundVariables/BoundScope.cpp b/src/Binder/BoundVariables/BoundScope.cpp index 93f0fd8..4bc76e7 100644 --- a/src/Binder/BoundVariables/BoundScope.cpp +++ b/src/Binder/BoundVariables/BoundScope.cpp @@ -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)); } diff --git a/src/Evaluator/EvalValues/NumericEvalValue.cpp b/src/Evaluator/EvalValues/NumericEvalValue.cpp index b174b6f..1d000ad 100644 --- a/src/Evaluator/EvalValues/NumericEvalValue.cpp +++ b/src/Evaluator/EvalValues/NumericEvalValue.cpp @@ -82,8 +82,11 @@ namespace Porygon::Evaluation { EvalValue *NumericEvalValue::Cast(shared_ptr castType) const { if (castType->GetClass() == TypeClass::Number){ auto num = static_pointer_cast(castType); - if (num->IsFloat()){ - return new NumericEvalValue(std::get(_intValue)); + if (num->IsFloat() && !this->_isFloat){ + return new NumericEvalValue(static_cast(std::get(_intValue))); + } + else if(!num->IsFloat() && this->_isFloat){ + return new NumericEvalValue(static_cast(std::get(_floatValue))); } } return EvalValue::Cast(castType);