mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
[dart2wasm] Fix canonicalization of concatenations with constants
New passing test: co19/Language/Expressions/Object_Identity/string_t01 Change-Id: I9e7758af30d1b11d136586090b82497c292cb1e3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286402 Reviewed-by: Aske Simon Christensen <askesc@google.com> Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
parent
88ac4a27a1
commit
095317db58
|
@ -2670,10 +2670,22 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
|
|||
@override
|
||||
w.ValueType visitStringConcatenation(
|
||||
StringConcatenation node, w.ValueType expectedType) {
|
||||
if (node.expressions.every((expr) => expr is StringLiteral)) {
|
||||
bool isConstantString(Expression expr) =>
|
||||
expr is StringLiteral ||
|
||||
(expr is ConstantExpression && expr.constant is StringConstant);
|
||||
|
||||
String extractConstantString(Expression expr) {
|
||||
if (expr is StringLiteral) {
|
||||
return expr.value;
|
||||
} else {
|
||||
return ((expr as ConstantExpression).constant as StringConstant).value;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.expressions.every(isConstantString)) {
|
||||
StringBuffer result = StringBuffer();
|
||||
for (final expr in node.expressions) {
|
||||
result.write((expr as StringLiteral).value);
|
||||
result.write(extractConstantString(expr));
|
||||
}
|
||||
final expr = StringLiteral(result.toString());
|
||||
return visitStringLiteral(expr, expectedType);
|
||||
|
|
Loading…
Reference in a new issue