Skip to content

Commit c644037

Browse files
authored
Fix compile error when using dart_style with analyzer 6.2.0. (#1414)
Fix #1413.
1 parent 3fcc65f commit c644037

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
## 2.3.6-wip
1+
## 2.3.6
22

3-
There are no user-visible changes in this release. The only changes are behind
4-
the `tall-style` experiment flag.
3+
* Fix compile error when using dart_style with analyzer 6.2.0.
54

65
## 2.3.5
76

lib/src/ast_extensions.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,25 @@ extension PatternExtensions on DartPattern {
409409
_ => false,
410410
};
411411
}
412+
413+
// TODO(rnystrom): This is a gross hack because dart_style 2.3.5 has a bad
414+
// analyzer constraint which allows dart_style to be used with a version of
415+
// analyzer that doesn't publicly expose the `.macroKeyword` getter.
416+
// Fortunately, the oldest analyzer that dart_style allows *does* have the
417+
// getter on the ClassDeclarationImpl class.
418+
//
419+
// To get users off that bad version, we're publishing a new version of
420+
// dart_style that has the same constraint and gracefully handles that getter
421+
// not statically being visible.
422+
//
423+
// This hack will be removed immediately after publishing a version with that
424+
// fix.
425+
extension ClassDeclarationExtensions on ClassDeclaration {
426+
/// If the [ClassDeclaration] is from a version of analyzer that has the
427+
/// `macroKeyword` getter and the class has a `macro` keyword, returns that
428+
/// token.
429+
///
430+
/// Otherwise, returns `null`.
431+
Token? get hackMacroKeywordForOlderAnalyzer =>
432+
(this as dynamic).macroKeyword as Token?;
433+
}

lib/src/cli/formatter_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'show.dart';
1111
import 'summary.dart';
1212

1313
// Note: The following line of code is modified by tool/grind.dart.
14-
const dartStyleVersion = '2.3.5';
14+
const dartStyleVersion = '2.3.6';
1515

1616
/// Global options that affect how the formatter produces and uses its outputs.
1717
class FormatterOptions {

lib/src/front_end/ast_node_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
248248
node.interfaceKeyword,
249249
node.finalKeyword,
250250
node.sealedKeyword,
251-
node.macroKeyword,
251+
node.hackMacroKeywordForOlderAnalyzer,
252252
node.mixinKeyword,
253253
node.classKeyword,
254254
],

lib/src/source_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ class SourceVisitor extends ThrowingAstVisitor {
592592
modifier(node.finalKeyword);
593593
modifier(node.sealedKeyword);
594594
modifier(node.mixinKeyword);
595-
modifier(node.macroKeyword);
595+
modifier(node.hackMacroKeywordForOlderAnalyzer);
596596
token(node.classKeyword);
597597
space();
598598
token(node.name);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dart_style
22
# Note: See tool/grind.dart for how to bump the version.
3-
version: 2.3.6-wip
3+
version: 2.3.6
44
description: >-
55
Opinionated, automatic Dart source code formatter.
66
Provides an API and a CLI tool.

0 commit comments

Comments
 (0)