Skip to content

Commit 50f903f

Browse files
committed
Merge branch 'main' into remove-bad-import-tests
# Conflicts: # CHANGELOG.md
2 parents f983c1f + b5a166e commit 50f903f

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import 'foo.dart' as prefix if (cond) 'bar.dart';
1010
```
1111

12+
* Don't force a space between `?` and `.` if a null-aware element contains a
13+
dot shorthand.
14+
1215
## 3.1.2
1316

1417
* Support dot shorthand syntax.

lib/src/front_end/ast_node_visitor.dart

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,18 +1605,7 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
16051605

16061606
@override
16071607
void visitNullAwareElement(NullAwareElement node) {
1608-
// A null-aware element containing a dot shorthand means there is a `?` and
1609-
// `.` next to each other. In that case, make sure we put a space between
1610-
// them so that they don't incorrectly get collapsed into a `?.` null-aware
1611-
// access token.
1612-
var space = switch (node.value) {
1613-
DotShorthandConstructorInvocation() => true,
1614-
DotShorthandInvocation() => true,
1615-
DotShorthandPropertyAccess() => true,
1616-
_ => false,
1617-
};
1618-
1619-
writePrefix(node.question, space: space, node.value);
1608+
writePrefix(node.question, node.value);
16201609
}
16211610

16221611
@override

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ environment:
99
sdk: ^3.7.0
1010

1111
dependencies:
12-
analyzer: ^8.0.0
12+
analyzer: ^8.1.0
1313
args: ^2.0.0
1414
collection: ^1.19.0
1515
package_config: ^2.1.0

test/tall/expression/collection_null_aware.stmt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,23 @@ var list = [
3131
### If the space between `?` and `.` is removed, it would become a single `?.`
3232
### token and thus a parse error.
3333
var list = [
34-
? . property ,
34+
?. property ,
3535
? . invocation ( ) ,
3636
? . new ( ) ,
3737
];
3838
<<< 3.10
3939
var list = [
40-
? .property,
41-
? .invocation(),
42-
? .new(),
40+
?.property,
41+
?.invocation(),
42+
?.new(),
4343
];
44+
>>> (experiment dot-shorthands) Ambiguous dot shorthand versus null-aware.
45+
### Because there is no space in "?.", it must be a null-aware access in a map.
46+
c = { e1 ?. e2 : e3 };
47+
<<< 3.10
48+
c = {e1?.e2: e3};
49+
>>> (experiment dot-shorthands) Ambiguous dot shorthand versus null-aware.
50+
### Because there is a space in "? .", it must be a dot shorthand in a set.
51+
c = { e1 ? . e2 : e3 };
52+
<<< 3.10
53+
c = {e1 ? .e2 : e3};

0 commit comments

Comments
 (0)