[Impl] 增加 prettyType,返回TypeInfo的FString, StructInstance自动输出父类TypeInfo
This commit is contained in:
@@ -107,7 +107,7 @@ namespace Fig
|
||||
u8"TypeError",
|
||||
std::format(
|
||||
"Type `List` indices must be `Int`, got '{}'",
|
||||
index->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(index).toBasicString()),
|
||||
ie->index);
|
||||
}
|
||||
List &list = base.get()->as<List>();
|
||||
@@ -142,7 +142,7 @@ namespace Fig
|
||||
u8"TypeError",
|
||||
std::format(
|
||||
"Type `String` indices must be `Int`, got '{}'",
|
||||
index->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(index).toBasicString()),
|
||||
ie->index);
|
||||
}
|
||||
FString &string = base.get()->as<ValueType::StringClass>();
|
||||
@@ -390,7 +390,7 @@ namespace Fig
|
||||
throw EvaluatorError(
|
||||
u8"TypeError",
|
||||
std::format("Condition must be boolean, got '{}'",
|
||||
condVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(condVal).toBasicString()),
|
||||
te->condition);
|
||||
}
|
||||
ValueType::BoolClass cond = condVal->as<ValueType::BoolClass>();
|
||||
@@ -477,7 +477,7 @@ namespace Fig
|
||||
std::format("In function '{}', default parameter '{}' has type '{}', which does not match the expected type '{}'",
|
||||
fnName.toBasicString(),
|
||||
fnParas.defParas[defParamIndex].first.toBasicString(),
|
||||
defaultVal->getTypeInfo().toString().toBasicString(),
|
||||
prettyType(defaultVal).toBasicString(),
|
||||
expectedType.toString().toBasicString()),
|
||||
fnArgs.argv[i]);
|
||||
}
|
||||
@@ -560,7 +560,7 @@ namespace Fig
|
||||
std::format("Function '{}' expects return type '{}', but got type '{}'",
|
||||
fnName.toBasicString(),
|
||||
fnStruct.retType.toString().toBasicString(),
|
||||
retVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(retVal).toBasicString()),
|
||||
fnStruct.body);
|
||||
}
|
||||
return retVal;
|
||||
@@ -750,7 +750,7 @@ namespace Fig
|
||||
initExpr->structName.toBasicString(),
|
||||
fieldName.toBasicString(),
|
||||
expectedType.toString().toBasicString(),
|
||||
defaultVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(defaultVal).toBasicString()),
|
||||
initExpr);
|
||||
}
|
||||
|
||||
@@ -767,7 +767,7 @@ namespace Fig
|
||||
initExpr->structName.toBasicString(),
|
||||
fieldName.toBasicString(),
|
||||
expectedType.toString().toBasicString(),
|
||||
argVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(argVal).toBasicString()),
|
||||
initExpr);
|
||||
}
|
||||
instanceCtx->def(fieldName, expectedType, field.am, argVal);
|
||||
@@ -806,7 +806,7 @@ namespace Fig
|
||||
initExpr->structName.toBasicString(),
|
||||
fieldName.toBasicString(),
|
||||
expectedType.toString().toBasicString(),
|
||||
defaultVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(defaultVal).toBasicString()),
|
||||
initExpr);
|
||||
}
|
||||
|
||||
@@ -823,7 +823,7 @@ namespace Fig
|
||||
initExpr->structName.toBasicString(),
|
||||
fieldName.toBasicString(),
|
||||
field.type.toString().toBasicString(),
|
||||
argVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(argVal).toBasicString()),
|
||||
initExpr);
|
||||
}
|
||||
instanceCtx->def(fieldName, field.type, field.am, argVal);
|
||||
@@ -926,7 +926,7 @@ namespace Fig
|
||||
"Variable `{}` expects init-value type `{}`, but got '{}'",
|
||||
varDef->name.toBasicString(),
|
||||
declaredTypeName.toBasicString(),
|
||||
value->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(value).toBasicString()),
|
||||
varDef->expr);
|
||||
}
|
||||
else if (value == nullptr)
|
||||
@@ -1040,7 +1040,7 @@ namespace Fig
|
||||
u8"TypeError",
|
||||
std::format(
|
||||
"Condition must be boolean, but got '{}'",
|
||||
condVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(condVal).toBasicString()),
|
||||
ifSt->condition);
|
||||
}
|
||||
if (condVal->as<ValueType::BoolClass>())
|
||||
@@ -1057,7 +1057,7 @@ namespace Fig
|
||||
u8"TypeError",
|
||||
std::format(
|
||||
"Condition must be boolean, but got '{}'",
|
||||
condVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(condVal).toBasicString()),
|
||||
ifSt->condition);
|
||||
}
|
||||
if (elifCondVal->as<ValueType::BoolClass>())
|
||||
@@ -1082,7 +1082,7 @@ namespace Fig
|
||||
u8"TypeError",
|
||||
std::format(
|
||||
"Condition must be boolean, but got '{}'",
|
||||
condVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(condVal).toBasicString()),
|
||||
whileSt->condition);
|
||||
}
|
||||
if (!condVal->as<ValueType::BoolClass>())
|
||||
@@ -1128,7 +1128,7 @@ namespace Fig
|
||||
u8"TypeError",
|
||||
std::format(
|
||||
"Condition must be boolean, but got '{}'",
|
||||
condVal->getTypeInfo().toString().toBasicString()),
|
||||
prettyType(condVal).toBasicString()),
|
||||
forSt->condition);
|
||||
}
|
||||
if (!condVal->as<ValueType::BoolClass>())
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Fig
|
||||
return id == other.id;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TypeInfoHash
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -69,6 +69,14 @@ namespace Fig
|
||||
}
|
||||
}
|
||||
|
||||
FString prettyType(ObjectPtr obj)
|
||||
{
|
||||
auto t = obj->getTypeInfo();
|
||||
if (t == ValueType::StructInstance)
|
||||
return obj->as<StructInstance>().parentType.toString();
|
||||
return t.toString();
|
||||
}
|
||||
|
||||
const TypeInfo ValueType::Any(FString(u8"Any"), true); // id: 1
|
||||
const TypeInfo ValueType::Null(FString(u8"Null"), true); // id: 2
|
||||
const TypeInfo ValueType::Int(FString(u8"Int"), true); // id: 3
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace Fig
|
||||
using ObjectPtr = std::shared_ptr<Object>;
|
||||
using List = std::vector<ObjectPtr>;
|
||||
|
||||
FString prettyType(ObjectPtr obj);
|
||||
|
||||
struct ValueKey
|
||||
{
|
||||
ObjectPtr value;
|
||||
|
||||
Reference in New Issue
Block a user