Skip to content

[Dot Shorthands] prefer_const_constructors #60963

Open
@RohitSaily

Description

@RohitSaily

Dart SDK version: 3.9.0-252.0.dev (dev) (Thu Jun 19 05:08:58 2025 -0700) on "macos_x64"

Analyzer via VSCode with lint rule prefer_const_constructors enabled

class A
{	A():
		cannotBeConst=0;
	int cannotBeConst;
}
extension type const B(A a)
	{}
B get b=>
	.new(A()); // Nonexpected error `prefer_const_constructors` :(

The lint rule prefer_const_constructors should not be triggered here because const cannot be used in this case. This is only an issue when the dot shorthand .new is used

B get b=>
	B(A()); // no dot-shorthand, no error :)

Metadata

Metadata

Assignees

Labels

area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagefeature-dot-shorthandsImplementation of the dot shorthands feature.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions