@@ -11,6 +11,21 @@ extension on ClassMember {
11
11
bool get isPrivate => ! isPublic;
12
12
}
13
13
14
+ // TODO(https://github.com/dart-lang/native/issues/1164): Kotlin compiler
15
+ // appends the method name with a dash and a hash code when arguments contain
16
+ // inline classes. This is because inline classes do not have any runtime type
17
+ // and the typical operator overloading supported by JVM cannot work for them.
18
+ //
19
+ // Once we support inline classes, we can relax the following constraints.
20
+ final _validDartIdentifier = RegExp (r'^[a-zA-Z_$][a-zA-Z0-9_$]*$' );
21
+
22
+ extension on String {
23
+ bool get isInvalidDartIdentifier =>
24
+ ! _validDartIdentifier.hasMatch (this ) &&
25
+ this != '<init>' &&
26
+ this != '<clinit>' ;
27
+ }
28
+
14
29
class Excluder extends Visitor <Classes , void > {
15
30
final Config config;
16
31
@@ -24,6 +39,11 @@ class Excluder extends Visitor<Classes, void> {
24
39
if (excluded) {
25
40
log.fine ('Excluded class ${classDecl .binaryName }' );
26
41
}
42
+ if (classDecl.name.isInvalidDartIdentifier) {
43
+ log.warning ('Excluded class ${classDecl .binaryName }: the name is not a'
44
+ ' valid Dart identifer' );
45
+ return true ;
46
+ }
27
47
return excluded;
28
48
});
29
49
final classExcluder = _ClassExcluder (config);
@@ -51,6 +71,12 @@ class _ClassExcluder extends Visitor<ClassDecl, void> {
51
71
if (excluded) {
52
72
log.fine ('Excluded method ${node .binaryName }#${method .name }' );
53
73
}
74
+ if (method.name.isInvalidDartIdentifier) {
75
+ log.warning (
76
+ 'Excluded method ${node .binaryName }#${method .name }: the name is not'
77
+ ' a valid Dart identifer' );
78
+ return false ;
79
+ }
54
80
return ! excluded;
55
81
}).toList ();
56
82
node.fields = node.fields.where ((field) {
@@ -59,6 +85,12 @@ class _ClassExcluder extends Visitor<ClassDecl, void> {
59
85
if (excluded) {
60
86
log.fine ('Excluded field ${node .binaryName }#${field .name }' );
61
87
}
88
+ if (field.name.isInvalidDartIdentifier) {
89
+ log.warning (
90
+ 'Excluded field ${node .binaryName }#${field .name }: the name is not'
91
+ ' a valid Dart identifer' );
92
+ return false ;
93
+ }
62
94
return ! excluded;
63
95
}).toList ();
64
96
}
0 commit comments