Dart2js brackets Symbol in metadata annotation

Issue

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?:

  1. (Dart VM) because I can run it at all.
  2. (dart2js) because it doesn’t compile to js.

update: I reported this bug

Solution

I think it’s a bug in Dart2JS because an operator should be allowed at this position.

Answered By – Günter Zöchbauer

Answer Checked By – Dawn Plyler (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *