Skip to content

名前空間上で属性が評価されていない #994

@poppingmoon

Description

@poppingmoon

#892 でパーサーが名前空間内の属性付き宣言をパースできるようになりましたが、インタープリターの collectNsMember では属性が無視されています。

__eval 内の宣言についての部分を見ると、右辺の式を評価した後に、宣言に付いている属性を評価して、右辺の値の attr パラメータを属性の値に書き換えていることがわかります。

if (node.attr.length > 0) {
const attrs: Value['attr'] = [];
for (const nAttr of node.attr) {
const value = await this._eval(nAttr.value, scope, callStack);
assertValue(value);
attrs.push({
name: nAttr.name,
value,
});
}
value.attr = attrs;
}

一方で、 collectNsMember の対応する部分を見ると、式を評価した後、そのままスコープに追加していることがわかります。

case 'def': {
if (node.dest.type !== 'identifier') {
throw new AiScriptNamespaceError('Destructuring assignment is invalid in namespace declarations.', node.loc.start);
}
if (node.mut) {
throw new AiScriptNamespaceError('No "var" in namespace declaration: ' + node.dest.name, node.loc.start);
}
const value = await this._eval(node.expr, nsScope, []);
assertValue(value);
if (
node.expr.type === 'fn'
&& isFunction(value)
&& !value.native
) {
value.name = nsScope.getNsPrefix() + node.dest.name;
}
this.define(nsScope, node.dest, value, node.mut);
break;
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions