Allow nil to be set to nullable types
This commit is contained in:
parent
2cd787c536
commit
62be1c78f3
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue