I want to create a symbol equal to that of a private MethodMirror's simplename. However, Symbol's documentation states the argument of new Symbol must be a valid public identifier. If I try and create a const Symbol('_privateIdentifier')
dart editor informs me that evaluation of this constant expression will throw an exception - though the program runs fine, and I am able to use it without any issues.
void main(){
//error flagged in dart editor, though runs fine.
const s = const Symbol('_s');
print(s); //Symbol("_s");
}
It seems the mirror system uses symbols.
import 'dart:mirrors';
class ClassA{
_privateMethod(){}
}
void main(){
var classMirror = reflect(new ClassA()).type;
classMirror.declarations.keys.forEach(print);
//Symbol("_privateMethod"), Symbol("ClassA")
}
Is the documentation/error flagging in dart editor a legacy bug due to an outdated dart analyzer? Or are there plans to enforce this public requirement in future? Is there another way to create a unique identifying symbol that will be minified to the same symbol as the declaration's simple name