Skip to content

Making named arguments quick fix results in invalid code #60608

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

Open
stephane-archer opened this issue Apr 24, 2025 · 3 comments
Open

Making named arguments quick fix results in invalid code #60608

stephane-archer opened this issue Apr 24, 2025 · 3 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.

Comments

@stephane-archer
Copy link

class _InfoSection extends StatelessWidget {
  final FCPLibrary _finalCutLibrary;
  final Future<int> _finalCutLibrarySize;
  final Future<int> _renderFilesSize;
  final Future<int> _proxyMediaSize;
  final Future<int> _optimizedMediaSize;
  final Future<int> _opticalFLowFilesSize;

  const _InfoSection(
    this._finalCutLibrary,
    this._finalCutLibrarySize,
    this._renderFilesSize,
    this._proxyMediaSize,
    this._optimizedMediaSize,
    this._opticalFLowFilesSize,
  );
...
}

Making named arguments quick fix results in invalid code

expected code:

class _InfoSection extends StatelessWidget {
  final FCPLibrary _finalCutLibrary;
  final Future<int> _finalCutLibrarySize;
  final Future<int> _renderFilesSize;
  final Future<int> _proxyMediaSize;
  final Future<int> _optimizedMediaSize;
  final Future<int> _opticalFLowFilesSize;

  const _InfoSection({
    required FCPLibrary finalCutLibrary,
    required Future<int> finalCutLibrarySize,
    required Future<int> renderFilesSize,
    required Future<int> proxyMediaSize,
    required Future<int> optimizedMediaSize,
    required Future<int> opticalFLowFilesSize,
  })  : _opticalFLowFilesSize = opticalFLowFilesSize,
        _optimizedMediaSize = optimizedMediaSize,
        _proxyMediaSize = proxyMediaSize,
        _renderFilesSize = renderFilesSize,
        _finalCutLibrarySize = finalCutLibrarySize,
        _finalCutLibrary = finalCutLibrary;
...
}
@stephane-archer stephane-archer added the area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. label Apr 24, 2025
@bwilkerson
Copy link
Member

The current behavior is to convert each parameter to the form required this._finalCutLibrary. I'm guessing that the concern is that private named parameters can't be referenced outside the library in which the parameter is defined.

But in this case the class is private, so the constructor also can't be invokes outside the library, so the code is actually valid.

Is there a different problem that I'm not seeing?

@FMorschel
Copy link
Contributor

@bwilkerson, the code above (and the following after this.) trigger private_optional_parameter:

class A {
  final int _field;
  A({required this._field});
}
Named parameters can't start with an underscore. dart private_optional_parameter

@bwilkerson
Copy link
Member

I thought I had a use case earlier where there was a private named parameter and there was no diagnostic. I can't reproduce that behavior now, so I must have done something other than what I thought I had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
Projects
None yet
Development

No branches or pull requests

3 participants