-
Notifications
You must be signed in to change notification settings - Fork 1.7k
String.fromCharCode
and String.fromCharCodes
should be const
constructors
#49407
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
Comments
Making Doesn't mean we can't do it, it just requires special-casing in the compilers, the magic doesn't happen in the constructor, How about:
Then you do const codePerson = char(0x1f9d1);
const charPerson = "$codePerson"; (Hmm, that does mean that views need to have const constructors. Might be an issue.) |
@lrhn Some questions: Q1: So can Q2: I don't get why making class Foo {
final Iterable<int> ints;
const Foo(this.ints);
}
const aFoo = Foo([1,2,3]); As far as evaluation goes, if we can spread constant Iterables, there must be a mechanism in the compiler for accessing the elements of the constant operand. |
The A plain generative Dart const constructor is limited in what it can do. It can create an instance of the class it's on, and it can fill in (necessarily final) fields by evaluating only potentially constant expressions. There is no way to write a generative To have That's not impossible. We do it for It might be possible to handle it entirely in the front-end, effectively rewriting So, this is a front-end request more than a library request. |
I suggested at some point that this should be an SDK issue with 'area-library' (rather than a language repo issue) because I would not expect the language specification to mention it, not because I thought that it could be implemented without going outside the language. This is similar to, e.g., Maybe, if adopted and scheduled for implementation, it's an 'area-meta' with sub-issues in 'area-library' and in 'area-front-end'? |
I have needed to construct constant expression strings from their code points.
This usually happens in programs that do some string processing with code points.
Sometimes it is desired to define named constants for both the code unit and the String.
This is currently impossible to construct a constant String form a code point, and impossible construct a const code point from a String. This leads to constants that are not obviously consistent:
These could be correct by construction:
dart-lang/language#2219 proposes making
aString.codeUnitAt(anInt)
a potentially constant expression, permittingHowever, using
String.codeUnitAt
has a UTF-16 pitfall. The following is correctwhereas this not:
This request is broken out from dart-lang/language#2219 (comment)
The text was updated successfully, but these errors were encountered: