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.26k stars 1.58k forks source link

Analysis server seems to cache case-sensitive package name #51908

Open ChristianKleineidam opened 1 year ago

ChristianKleineidam commented 1 year ago

I'm getting the following error that doesn't make sense:

The argument type 'LexemeFlashBloc (where LexemeFlashBloc is defined in C:\Users\Christian\Documents\Programming\speedy\lib\blocs\lexeme_flash_bloc.dart)' can't be assigned to the parameter type 'LexemeFlashBloc (where LexemeFlashBloc is defined in C:\Users\Christian\Documents\Programming\Speedy\lib\blocs\lexeme_flash_bloc.dart)'. (Documentation) 
LexemeFlashBloc is defined in C:\Users\Christian\Documents\Programming\speedy\lib\blocs\lexeme_flash_bloc.dart (lexeme_flash_bloc.dart:8).
LexemeFlashBloc is defined in C:\Users\Christian\Documents\Programming\Speedy\lib\blocs\lexeme_flash_bloc.dart (lexeme_flash_bloc.dart:8).

I have created LexemeRepository in a file containing:

import 'package:speedy/blocs/lexeme_flash_bloc.dart';

class LexemeRepository {
  LexemeFlashBloc? lexemeFlashBloc;

  register(LexemeFlashBloc bloc) {}
}

In another file I have:

class LexemeFlashBloc extends Bloc<LexemeFlashEvent, LexemeFlashState> {
  final LexemeRepository lexemeRepository;

   registerBloc()  {
    LexemeFlashBloc lexemeFlashBloc = this;
    lexemeRepository.register(lexemeFlashBloc);
  }
...

It underlines (lexemeFlashBloc) and shows me the error for that.

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 3.8.0-1.0.pre.10, on Microsoft Windows [Version 10.0.22621.1413], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.25)
[√] Android Studio (version 2021.1)
[√] VS Code (version 1.75.0)
[√] Connected device (3 available)
[√] HTTP Host Availability
bwilkerson commented 1 year ago

Dart has defined library equality to be based on the resolved URI used to refer to the library, and URI's are case sensitive. The two URI's used to refer to the library, even though they resolve to the same file on disk, are taken to be distinct because of the case difference between 'speedy' and 'Speedy'.

ChristianKleineidam commented 1 year ago

I did setup the project initially with the name "Speedy" and then changed it to "speedy" after some process complained about the casing. Now when I search in my project for "Speedy" in a case-sensitive way.

It seems like somehow "import 'package:speedy/blocs/lexeme_flash_bloc.dart';" applies that it's in "\Users\Christian\Documents\Programming\Speedy\lib\blocs\lexeme_flash_bloc.dart'

bwilkerson commented 1 year ago

If either (a) you haven't run pub since updating the name or (b) the name of the directory on disk is still uppercase, then that might account for the issue.

ChristianKleineidam commented 1 year ago

I have run pub and the directory on the disk is in lowercase.

bwilkerson commented 1 year ago

Then I'm at a loss to explain it. The one thing I can think of is that the tool might have cached the older version of the URI in the .dartServer directory in your home directory. You can safely delete the contents of that directory, though it will be slower than normal to re-analyze everything. If that doesn't work then I'll have to hope someone else knows what's going on.

ChristianKleineidam commented 1 year ago

I did delete the .dartServer directory which had an amazing number of files in it but that didn't help either.

ChristianKleineidam commented 1 year ago

I copied my whole project into a new folder and now it works. I still have the old folder. Even when this solved the issue on my end, it seems that there's a bug if copying the project into a different folder solves the issue.

bwilkerson commented 1 year ago

I agree. There's definitely a bug somewhere.

@scheglov In case you have any insights to offer.