New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow trailing = in symbol literals #13640
Comments
Added Accepted label. |
This comment was originally written by @mhausner I proposed to write Symbol literals as #"abc" instead of #abc. This would make #"abc=" a regular case, and we could also express operator symbols as literals. I think it also expresses better what a symbol literal is: a string (with some special semantics for compilers). Lastly, it is similar syntax to raw strings. Thinking about the last point some more, we could also define symbol literals as s"abc". But I won't push my luck any further here. |
This comment was originally written by @seaneagan String syntax might make people think they can put any String, not just identifiers, and that it returns an actual String, as opposed to a Symbol. What do you mean by "regular case"? Why couldn't operator symbols be exposed with (an extension of) the current syntax? #() unary - is always tricky, maybe: #-1 |
This comment was originally written by @seaneagan Oh, my bad, looks like the spec already allows operator symbol literals! |
Still valid, there is no way to express the symbol for a private setter. You can get a private getter name as You need an elaborate void main() {
print(#_foo);
print(const Symbol("foo="));
print(_fooSetSymbol);
}
final Symbol _fooSetSymbol = symbolOf((d) => d._foo = 0);
// Imagine it's in another library, so `_last` won't get in the way.
Symbol symbolOf(void Function(dynamic target) access) {
var s = _Symbolizer();
access(s);
return s._last ?? (throw StateError("No member access"));
}
class _Symbolizer {
Symbol? _last;
noSuchMethod(Invocation invocation) {
_last = invocation.memberName;
}
} |
Right, but then I can see that we need an issue for dart2js: #54603. |
symbolLiteral:
‘#’ (operator | (identifier (‘.’ identifier)*) '='?)
Would be nice to say
classMirror.members[#setter=]
The text was updated successfully, but these errors were encountered: