From 2956b1a705953f880a5dae9d3a0969df0fc45e99 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Thu, 25 May 2023 16:16:51 -0700 Subject: [PATCH] Don't drop "?" on nullable empty record types. (#1229) Fix #1224. --- CHANGELOG.md | 1 + lib/src/source_visitor.dart | 1 + test/whitespace/record_types.unit | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1854edd..e78d5cee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Don't split before `.` following a record literal (#1213). * Don't force split on a line comment before a switch expression case (#1215). * Require `package:analyzer` `^5.12.0`. +* Preserve `?` on nullable empty record types (#1224). # 2.3.1 diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart index fefaae18..09aa81e3 100644 --- a/lib/src/source_visitor.dart +++ b/lib/src/source_visitor.dart @@ -2505,6 +2505,7 @@ class SourceVisitor extends ThrowingAstVisitor { if (node.rightParenthesis.precedingComments != null) soloZeroSplit(); token(node.rightParenthesis); + token(node.question); return; } diff --git a/test/whitespace/record_types.unit b/test/whitespace/record_types.unit index 8f2efd54..74aed599 100644 --- a/test/whitespace/record_types.unit +++ b/test/whitespace/record_types.unit @@ -47,4 +47,8 @@ >>> nullable record type ( int , bool ) ? x; <<< -(int, bool)? x; \ No newline at end of file +(int, bool)? x; +>>> empty nullable record type +( ) ? x; +<<< +()? x; \ No newline at end of file