You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[code_builder] Chained cascade after nullable type cast emits ?.. syntax error #2693
Chaining .cascade(...) or .cascadeIndex(...) after an assignment whose right-hand side ends with a ? token (such as an unparenthesized nullable cast as T?, or asA once #1140 lands) emits as T?..nextField, which the Dart scanner lexes as the ?.. null-aware cascade operator on T.
Impact: Code generators emitting cascaded setter assignments (such as package:json_serializable) produce unparseable Dart output that crashes DartFormatter unless every cascaded RHS is manually padded with a trailing space (Code('${expr} ')).
Proposed Fix
In ExpressionEmitter.visitBinaryExpression (or by introducing a dedicated leading-space flag on cascade / cascadeIndex when chained onto an assignment/binary expression), emit a separating space (or newline) before .. / ?.. when expression.operator is '..' or '?..' and expression.left is a cascade assignment or ends with ?.
Minimal reproduction & DartFormatter error
import'package:code_builder/code_builder.dart';
import'package:dart_style/dart_style.dart';
voidmain() {
final expr =refer('Foo').call([])
.cascade('a').assign(constCodeExpression(Code("json['a'] as int?")))
.cascade('b').assign(literalNum(1));
final raw = expr.accept(DartEmitter(useNullSafetySyntax:true)).toString();
print(raw); // Foo()..a = json['a'] as int?..b = 1// Throws FormatterException: Can't Have type arguments on the receiver of a// null-aware cascade / Expected ';' after this.DartFormatter(languageVersion:DartFormatter.latestLanguageVersion)
.formatStatement('$raw;');
}
Activity