Allow nil to be set to nullable types

This commit is contained in:
Deukhoofd 2019-09-22 15:19:58 +02:00
parent 2cd787c536
commit 62be1c78f3
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 12 additions and 1 deletions

View File

@ -27,6 +27,11 @@ namespace Porygon::Evaluation{
inline std::size_t GetHashCode() const final{
return 0;
}
public:
EvalValue *Cast(shared_ptr<const ScriptType> castType) const override {
return this->Clone();
}
};
}

View File

@ -50,9 +50,16 @@ namespace Porygon{
}
CastResult ScriptType::CastableTo(const shared_ptr<const ScriptType> &castType, bool explicitCast) const {
if (this->operator==(castType))
return CastResult ::Unchanged;
if (_class == TypeClass::Any){
return CastResult ::UncheckedCast;
}
if (_class == TypeClass::Nil){
auto otherClass = castType->GetClass();
if (otherClass != TypeClass::Number && otherClass != TypeClass::Bool)
return CastResult ::ValidCast;
}
if (explicitCast)
return CastResult::InvalidCast;
return CastResult::InvalidCast;
@ -60,7 +67,6 @@ namespace Porygon{
std::string ScriptType::ToString(TypeClass c) {
switch (c){
case TypeClass::Error: return "error";
case TypeClass::Nil: return "nil";
case TypeClass::Number: return "number";