I can run this code on 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"];
}
output:
[42]
[Dart]
But when i try to compile it with dart2js it fails with this error:
[Error from Dart2JS]:
bin\dart2jswithbracketanotation.dart:9:7:
Expected identifier, but got '['.
@Tag(#[])
So which one has the bug?:
update: I reported this bug
I think it's a bug in Dart2JS because an operator should be allowed at this position.