From 4c58ddf813db75f5ab7c092ae6823832aba4828b Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Mon, 21 Aug 2023 11:40:38 -0700 Subject: [PATCH] Fix regression in splitting type annotations with library prefixes. (#1250) * Fix regression in splitting type annotations with library prefixes. Fix #1249. * Require Dart 3.0. * Stop testing on 2.19 and move to 3.0. --- .github/workflows/test-package.yml | 4 ++-- CHANGELOG.md | 1 + lib/src/source_visitor.dart | 13 +++++-------- pubspec.yaml | 2 +- test/regression/0100/0108.unit | 6 +++--- test/regression/1200/1249.unit | 13 +++++++++++++ 6 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 test/regression/1200/1249.unit diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml index 8ede58ae..58b98ff9 100644 --- a/.github/workflows/test-package.yml +++ b/.github/workflows/test-package.yml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [2.19.0, dev] + sdk: [3.0.0, dev] steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f @@ -50,7 +50,7 @@ jobs: matrix: # Add macos-latest and/or windows-latest if relevant for this package. os: [ubuntu-latest] - sdk: [2.19.0, dev] + sdk: [3.0.0, dev] steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 - uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f diff --git a/CHANGELOG.md b/CHANGELOG.md index f827cb75..bbdd1347 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 2.3.3-dev * Remove support for `inline class` since that syntax has changed. +* Fix regression in splitting type annotations with library prefixes (#1249). ## 2.3.2 diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart index b7098777..d0405223 100644 --- a/lib/src/source_visitor.dart +++ b/lib/src/source_visitor.dart @@ -2251,22 +2251,19 @@ class SourceVisitor extends ThrowingAstVisitor { @override void visitNamedType(NamedType node) { - var importPrefix = node.importPrefix; - if (importPrefix != null) { + if (node.importPrefix case var importPrefix?) { builder.startSpan(); - token(importPrefix.name); soloZeroSplit(); token(importPrefix.period); + token(node.name2); + builder.endSpan(); + } else { + token(node.name2); } - token(node.name2); visit(node.typeArguments); token(node.question); - - if (importPrefix != null) { - builder.endSpan(); - } } @override diff --git a/pubspec.yaml b/pubspec.yaml index 1456a3f7..e114401f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ description: >- Provides an API and a CLI tool. repository: https://github.com/dart-lang/dart_style environment: - sdk: ">=2.19.0 <3.0.0" + sdk: "^3.0.0" dependencies: analyzer: '>=5.12.0 <7.0.0' diff --git a/test/regression/0100/0108.unit b/test/regression/0100/0108.unit index b71b705e..fb55d67c 100644 --- a/test/regression/0100/0108.unit +++ b/test/regression/0100/0108.unit @@ -212,13 +212,13 @@ async.Future> call(String tag, List cssUrls, {Typ DDC$RT.type((Iterable> _) {}), key: "Cast failed: package:angular/core_dom/component_css_loader.dart:17:25"))), DDC$RT.type((Future> _) {}), key: "Cast failed: package:angular/core_dom/component_css_loader.dart:17:7")); <<< -async.Future> call(String tag, List cssUrls, {Type type}) => +async.Future> call(String tag, List cssUrls, + {Type type}) => (DDC$RT.cast( async.Future.wait((DDC$RT.cast( cssUrls.map((url) => _styleElement( tag, - (DDC$RT.cast(url, String, - key: "Cast failed: package:angular/core_dom/component_css_loader.dart:17:65")), + (DDC$RT.cast(url, String, key: "Cast failed: package:angular/core_dom/component_css_loader.dart:17:65")), type)), DDC$RT.type((Iterable> _) {}), key: "Cast failed: package:angular/core_dom/component_css_loader.dart:17:25"))), diff --git a/test/regression/1200/1249.unit b/test/regression/1200/1249.unit new file mode 100644 index 00000000..fe64601b --- /dev/null +++ b/test/regression/1200/1249.unit @@ -0,0 +1,13 @@ +>>> +class C { + late final _callocPtr = _lookup< + ffi + .NativeFunction>( + 'calloc'); +} +<<< +class C { + late final _callocPtr = _lookup< + ffi.NativeFunction< + ffi_Pointer_ffi_Void_ Function(ffi_Size__ffi_Size)>>('calloc'); +}