修改LvObject set方法,先检查是否可变再检查类型匹配。更符合直觉
This commit is contained in:
@@ -80,6 +80,10 @@ namespace Fig
|
|||||||
if (kind == Kind::Variable)
|
if (kind == Kind::Variable)
|
||||||
{
|
{
|
||||||
auto s = resolve(slot);
|
auto s = resolve(slot);
|
||||||
|
if (isAccessConst(s->am))
|
||||||
|
{
|
||||||
|
throw RuntimeError(FString(std::format("Variable `{}` is immutable", s->name.toBasicString())));
|
||||||
|
}
|
||||||
if (!isTypeMatch(s->declaredType, v, ctx))
|
if (!isTypeMatch(s->declaredType, v, ctx))
|
||||||
{
|
{
|
||||||
throw RuntimeError(
|
throw RuntimeError(
|
||||||
@@ -89,11 +93,6 @@ namespace Fig
|
|||||||
s->declaredType.toString().toBasicString(),
|
s->declaredType.toString().toBasicString(),
|
||||||
prettyType(v).toBasicString())));
|
prettyType(v).toBasicString())));
|
||||||
}
|
}
|
||||||
if (isAccessConst(s->am))
|
|
||||||
{
|
|
||||||
throw RuntimeError(FString(
|
|
||||||
std::format("Variable `{}` is immutable", s->name.toBasicString())));
|
|
||||||
}
|
|
||||||
s->value = v;
|
s->value = v;
|
||||||
}
|
}
|
||||||
else if (kind == Kind::ListElement)
|
else if (kind == Kind::ListElement)
|
||||||
|
|||||||
Reference in New Issue
Block a user