gpt4 book ai didi

dart - Dart2js在元数据注释中将符号括起来

转载 作者:行者123 更新时间:2023-12-03 03:46:32 25 4
gpt4 key购买 nike

我可以在Dart VM上运行以下代码:

@MirrorsUsed(metaTargets: Tag)
import 'dart:mirrors';

class Tag {
final Symbol name;
const Tag(this.name);
}
@proxy
@Tag(#[])
class Tagged {
noSuchMethod(Invocation invocation) {
InstanceMirror instanceMirror = reflect(this);
ClassMirror classMirror = instanceMirror.type;
classMirror.metadata.forEach((em) {
if (em.reflectee is Tag && em.reflectee.name == invocation.memberName)
print(invocation.positionalArguments);
});
}
}
void main() {
var tagged = new Tagged();
tagged[42];
tagged.foo();
tagged["Dart"];
}

输出:

[42]
[Dart]



但是,当我尝试使用dart2js对其进行编译时,它会因以下错误而失败:

[Error from Dart2JS]:
bin\dart2jswithbracketanotation.dart:9:7:
Expected identifier, but got '['.
@Tag(#[])



那么哪个有bug ?:
  • (Dart VM),因为我完全可以运行它。
  • (dart2js),因为它无法编译为js。

  • 更新: I reported this bug

    最佳答案

    我认为这是Dart2JS中的错误,因为应该在此位置允许一个运算符。

    关于dart - Dart2js在元数据注释中将符号括起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24107533/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com