dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.06k stars 1.55k forks source link

Analyzer crashes when a file contains both a `part` and `part of` in the same file. #54931

Open Abdurrahman98XX opened 6 months ago

Abdurrahman98XX commented 6 months ago
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.3.0-279.3.beta (beta) (Wed Jan 31 15:24:56 2024 +0000) on "windows_x64"
- on windows / "Windows 10 Pro" 10.0 (Build 22631)
- locale is en-US

#### Project info

- sdk constraint: '>=3.1.5 <4.0.0'
- dependencies: animations, blurhash_dart, convert, crypto, cupertino_icons, dio, equatable, flutter, flutter_localizations, flutter_riverpod, flutter_svg, go_router, image, intl, json_annotation, riverpod_annotation, shared_preferences, system_theme
- dev_dependencies: build_runner, custom_lint, flutter_gen_runner, flutter_lints, flutter_native_splash, flutter_test, json_serializable, riverpod_generator, riverpod_lint

#### Process info

| Memory | CPU | Elapsed time | Command line |
| -----: | --: | -----------: | ------------ |
|  91 MB |  -- |              | dart.exe     |
|  95 MB |  -- |              | dart.exe     |
|  96 MB |  -- |              | dart.exe     |

what causes issue is making file have a part and part of in the same file

Screenshot 2024-02-15 171717

some logs from LSP

---\lib\theme\theme_mode\state.dart
[Error - 5:16:07 PM] Request textDocument/inlayHint failed.
  Message: File is not being analyzed
  Code: -32007 
---\lib\theme\theme_mode\state.dart
[Error - 5:16:22 PM] Request textDocument/documentSymbol failed.
  Message: Analysis failed for file
  Code: -32013 
---\lib\theme\theme_mode\state.dart
[Error - 5:16:22 PM] The Dart Analysis Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

fixing it is by removing the unlogical syntax, the issue disappers but after ide restart

pq commented 6 months ago

@scheglov

scheglov commented 6 months ago

I cannot reproduce it. The test below reports some errors, but no crash.

  solo_test_X() async {
    newFile('$testPackageLibPath/a.dart', r'''
part 'test.dart';
''');

    await assertErrorsInCode(r'''
part 'a.dart';
part of 'a.dart';
''', [
      error(ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART, 15, 4),
    ]);
  }
eernstg commented 6 months ago

Hmmm, part 'a.dart'; part of 'a.dart'; is not derivable from <libraryDeclaration> and not derivable from <partDeclaration>, which would presumably make it a syntax error?

scheglov commented 6 months ago

Sorry, yes, you are right, there is a syntactic error. I was mostly saying that there is no crash, and kind of the diagnostic did not seem important then :-) I updated my previous message.