Fix issues with casting when type is the same.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a7fee1437c
commit
8c13c2c84c
|
@ -748,6 +748,9 @@ namespace Porygon::Binder {
|
|||
this->_scriptData->Diagnostics->LogInfo(Diagnostics::DiagnosticCode::UnvalidatedCast, exp->GetStartPosition(),
|
||||
exp->GetLength());
|
||||
}
|
||||
else if (castResult == CastResult::Unchanged){
|
||||
return toCastParameter;
|
||||
}
|
||||
return new BoundCastExpression(toCastParameter, destinationType);
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,13 @@ namespace Porygon::Evaluation {
|
|||
|
||||
[[nodiscard]]
|
||||
virtual EvalValue* Cast(shared_ptr<const ScriptType> castType) const{
|
||||
throw new EvaluationException("Casting to invalid type.");
|
||||
if (castType->GetClass() == this->GetTypeClass()){
|
||||
return this->Clone();
|
||||
}
|
||||
std::stringstream s;
|
||||
s << "Casting to invalid type. From: " << this->ToString();
|
||||
s << ". To: " << castType->ToString();
|
||||
throw EvaluationException(s.str());
|
||||
}
|
||||
|
||||
virtual std::string ToString() const{
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Porygon{
|
|||
InvalidCast,
|
||||
UncheckedCast,
|
||||
DataLoss,
|
||||
Unchanged,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,10 @@ namespace Porygon {
|
|||
diagnostics->LogWarning(Diagnostics::DiagnosticCode::DataLossOnCast, parameter->GetStartPosition(),
|
||||
parameter->GetLength());
|
||||
}
|
||||
else if(castResult == CastResult::Unchanged){
|
||||
parameters->at(i) = parameter;
|
||||
continue;
|
||||
}
|
||||
parameters->at(i) = new Binder::BoundCastExpression(parameter, _parameterTypes[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace Porygon{
|
|||
|
||||
[[nodiscard]] CastResult CastableTo(const shared_ptr<const ScriptType>& castType, bool explicitCast) const final{
|
||||
if (this->operator==(castType))
|
||||
return CastResult ::ValidCast;
|
||||
return CastResult ::Unchanged;
|
||||
if (!explicitCast){
|
||||
if (castType->GetClass() != TypeClass::Number )
|
||||
return CastResult::InvalidCast;
|
||||
|
|
Loading…
Reference in New Issue