Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running dart fix (Bad state: Missing a visit method for a node of type PatternAssignmentImpl) #56929

Open
Yegair opened this issue Oct 21, 2024 · 4 comments
Labels
analyzer-dartfix Issues with the dartfix package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@Yegair
Copy link

Yegair commented Oct 21, 2024

Just encountered this error when running dart fix --dry-run. Since I was prompted to do so, I opened this ticket.

I have to add that I tried dart fix --apply next which completed without an error, and since then I can no longer reproduce the issue (dart fix --dry-run no longer throws an error).

dart fix --dry-run
Computing fixes in app (dry run)...  
An unexpected error was encountered by the Analysis Server.
Please file an issue at https://github.com/dart-lang/sdk/issues/new/choose with the following details:

Internal error: Exception while using a UseBuildContextSynchronously to visit a MethodInvocationImpl in MethodInvocationImpl in ExpressionStatementImpl in BlockImpl in BlockFunctionBodyImpl in MethodDeclarationImpl in ClassDeclarationImpl in CompilationUnitImpl
Bad state: Missing a visit method for a node of type PatternAssignmentImpl
#0      ExitDetector.visitNode (package:analyzer/src/dart/resolver/exit_detector.dart:455:5)
#1      GeneralizingAstVisitor.visitCollectionElement (package:analyzer/dart/ast/visitor.dart:216:56)
#2      GeneralizingAstVisitor.visitExpression (package:analyzer/dart/ast/visitor.dart:313:42)
#3      GeneralizingAstVisitor.visitPatternAssignment (package:analyzer/dart/ast/visitor.dart:590:56)
#4      PatternAssignmentImpl.accept (package:analyzer/src/dart/ast/ast.dart:13465:50)
#5      ExitDetector._nodeExits (package:analyzer/src/dart/resolver/exit_detector.dart:663:17)
#6      ExitDetector.visitExpressionStatement (package:analyzer/src/dart/resolver/exit_detector.dart:178:7)
#7      ExpressionStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:6186:50)
#8      _extension#6.terminatesControl (package:linter/src/rules/use_build_context_synchronously.dart:1390:12)
#9      _extension#2.terminatesControl (package:linter/src/rules/use_build_context_synchronously.dart:1310:32)
#10     AsyncStateVisitor._visitIfLike (package:linter/src/rules/use_build_context_synchronously.dart:891:39)
#11     AsyncStateVisitor.visitIfStatement (package:linter/src/rules/use_build_context_synchronously.dart:470:53)
#12     IfStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:9378:50)
#13     AsyncStateVisitor._inOrderAsyncState (package:linter/src/rules/use_build_context_synchronously.dart:771:29)
#14     AsyncStateVisitor._inOrderAsyncStateGuardable (package:linter/src/rules/use_build_context_synchronously.dart:788:7)
#15     AsyncStateVisitor._visitBlockLike (package:linter/src/rules/use_build_context_synchronously.dart:799:35)
#16     AsyncStateVisitor.visitBlock (package:linter/src/rules/use_build_context_synchronously.dart:335:7)
#17     BlockImpl.accept (package:analyzer/src/dart/ast/ast.dart:2087:50)
#18     AsyncStateTracker.asyncStateFor (package:linter/src/rules/use_build_context_synchronously.dart:114:24)
#19     _Visitor.check (package:linter/src/rules/use_build_context_synchronously.dart:1097:42)
#20     _Visitor._visitArgumentList (package:linter/src/rules/use_build_context_synchronously.dart:1293:11)
#21     _Visitor.visitMethodInvocation (package:linter/src/rules/use_build_context_synchronously.dart:1263:5)
#22     MethodInvocationImpl.accept (package:analyzer/src/dart/ast/ast.dart:11870:50)
#23     LinterVisitor._runSubscriptions (package:analyzer/src/lint/linter_visitor.dart:1096:14)
#24     LinterVisitor.visitMethodInvocation (package:analyzer/src/lint/linter_visitor.dart:644:5)
#25     MethodInvocationImpl.accept (package:analyzer/src/dart/ast/ast.dart:11870:50)
#26     MethodInvocationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:11879:14)
#27     LinterVisitor.visitMethodInvocation (package:analyzer/src/lint/linter_visitor.dart:645:10)
#28     MethodInvocationImpl.accept (package:analyzer/src/dart/ast/ast.dart:11870:50)
#29     ExpressionStatementImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:6190:17)
#30     LinterVisitor.visitExpressionStatement (package:analyzer/src/lint/linter_visitor.dart:327:10)
#31     ExpressionStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:6186:50)
#32     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:12583:20)
#33     BlockImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2091:17)
#34     LinterVisitor.visitBlock (package:analyzer/src/lint/linter_visitor.dart:111:10)
#35     BlockImpl.accept (package:analyzer/src/dart/ast/ast.dart:2087:50)
#36     BlockFunctionBodyImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2047:12)
#37     LinterVisitor.visitBlockFunctionBody (package:analyzer/src/lint/linter_visitor.dart:117:10)
#38     BlockFunctionBodyImpl.accept (package:analyzer/src/dart/ast/ast.dart:2039:50)
#39     MethodDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:11693:10)
#40     LinterVisitor.visitMethodDeclaration (package:analyzer/src/lint/linter_visitor.dart:639:10)
#41     MethodDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:11685:50)
#42     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:12583:20)
#43     ClassDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2954:13)
#44     LinterVisitor.visitClassDeclaration (package:analyzer/src/lint/linter_visitor.dart:165:10)
#45     ClassDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:2944:50)
#46     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:12583:20)
#47     CompilationUnitImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:3614:21)
#48     LinterVisitor.visitCompilationUnit (package:analyzer/src/lint/linter_visitor.dart:189:10)
#49     CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:3607:50)
#50     LibraryAnalyzer._computeLints (package:analyzer/src/dart/analysis/library_analyzer.dart:398:12)
#51     LibraryAnalyzer._computeDiagnostics (package:analyzer/src/dart/analysis/library_analyzer.dart:323:7)
#52     LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:108:5)
#53     AnalysisDriver._analyzeFileImpl.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1400:11)
<asynchronous suspension>
#54     PerformanceLog.runAsync (package:analyzer/src/dart/analysis/performance_logger.dart:50:14)
<asynchronous suspension>
#55     AnalysisDriver._analyzeFile.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1314:9)
<asynchronous suspension>
#56     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:174:14)
<asynchronous suspension>
#57     AnalysisDriver._analyzeFile (package:analyzer/src/dart/analysis/driver.dart:1311:5)
<asynchronous suspension>
#58     AnalysisDriver._getErrors (package:analyzer/src/dart/analysis/driver.dart:1745:5)
<asynchronous suspension>
#59     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1213:7)
<asynchronous suspension>
#60     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2455:7)
<asynchronous suspension>


null
Nothing to fix!
dart info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

#### General info

- Dart 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "macos_arm64"
- on macos / Version 14.6.1 (Build 23G93)
- locale is en-DE

#### Project info

- sdk constraint: '>=3.5.3 <4.0.0'
- dependencies: badges, bloc, cached_network_image, characters, collection, confetti, connectivity_plus, cross_file, crypto, decimal, device_info_plus, diacritic, diffutil_dart, dio, dotted_border, dotted_line, drift, email_validator, equatable, facebook_app_events, fast_immutable_collections, firebase_analytics, firebase_auth, firebase_core, firebase_in_app_messaging, firebase_messaging, firebase_remote_config, fl_chart, flutter, flutter_animate, flutter_bloc, flutter_cache_manager, flutter_keyboard_visibility, flutter_launcher_icons, flutter_localizations, flutter_markdown, flutter_picker_plus, flutter_riverpod, flutter_staggered_grid_view, flutter_stream_listener, flutter_svg, freezed_annotation, go_router, google_sign_in, hive, hive_flutter, http, hydrated_bloc, image_picker, in_app_review, intl, json_annotation, keyboard_actions, logger, lottie, mime, mixpanel_flutter, package_info_plus, path, path_provider, path_to_regexp, percent_indicator, pin_code_fields, provider, purchases_flutter, responsive_framework, retry, riverpod_annotation, rxdart, sentry_flutter, share_plus, sign_in_with_apple, sliver_tools, sqlite3, sqlite3_flutter_libs, stream_channel, stream_transform, url_launcher, uuid, video_player, visibility_detector, wakelock_plus, webview_cookie_manager
- dev_dependencies: build_runner, custom_lint, drift_dev, file, flutter_lints, flutter_test, freezed, json_serializable, meta, patrol, patrol_finders, platform, riverpod_generator, riverpod_lint
- elided dependencies: 4

#### Process info

|   Memory |   CPU | Elapsed time | Command line                                                                               |
| -------: | ----: | -----------: | ------------------------------------------------------------------------------------------ |
|    13 MB |  0.0% |  04-03:56:32 | dart devtools --machine --allow-embedding --dtd-uri ws:<path>/zazJukNKK27qCbUq             |
|    59 MB |  0.0% |  04-03:56:35 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.98.1            |
|    39 MB |  0.0% |        16:25 | dart lib/custom_lint_client.dart ::1 61258                                                 |
|    11 MB |  0.0% |  04-03:56:35 | dart tooling-daemon --machine                                                              |
|    26 MB |  0.0% |  04-03:56:35 | flutter_tools.snapshot daemon                                                              |
|    43 MB |  0.2% |        10:27 | flutter_tools.snapshot debug_adapter                                                       |
| 21409 MB | 89.0% |  06-01:20:24 | flutter_tools.snapshot debug_adapter                                                       |
|    54 MB |  1.2% |        10:26 | flutter_tools.snapshot run --machine --start-paused --dart-define-from-file .env.dev.json -d 00008020-0009682E2181002E --devtools-server-address http:<path>/ --target <path>/main.dart |
flutter --version
Flutter 3.24.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 2663184aa7 (6 weeks ago) • 2024-09-11 16:27:48 -0500
Engine • revision 36335019a8
Tools • Dart 3.5.3 • DevTools 2.37.3
@dart-github-bot
Copy link
Collaborator

Summary: The user encountered an error "Bad state: Missing a visit method for a node of type PatternAssignmentImpl" while running dart fix --dry-run. The error was not reproducible after running dart fix --apply.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 21, 2024
@keertip
Copy link
Contributor

keertip commented Oct 21, 2024

@Yegair , thanks for the report. Do you have a list of fixes that were applied when dart fix --apply ran? What were the errors you were looking to fix?

@keertip keertip added analyzer-dartfix Issues with the dartfix package P3 A lower priority bug or feature request labels Oct 21, 2024
@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Oct 21, 2024
@Yegair
Copy link
Author

Yegair commented Oct 22, 2024

It did not fix any errors.

The reason I ran it was that I noted that VSCode stopped automatically adding const to constructors where possible on save, and I just wanted to know whether it was a VSCode or a Dart linter problem. It turned out that I was just missing a prefer_const_constructors: true in my analysis_options.yaml, which I assume was turned off by default in some recent update. However, I don't think this was related to the reported problem in any way.

@Yegair
Copy link
Author

Yegair commented Oct 22, 2024

Just discovered that I can reproduce the issue by running the build_runner and then running dart fix --dry-run afterwards. To be more specific, I ran the following 3 commands:

$ flutter pub run build_runner clean
$ flutter pub run build_runner build --delete-conflicting-outputs
$ dart fix --dry-run

And again running dart fix a second time does not cause the same error (no matter if I use --dry-run or --apply)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-dartfix Issues with the dartfix package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants