- Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Context: new syntax changes in dart-lang/language#4485 (comment):
Erik wrote the following -
The ambiguity associated with methods named
factoryhas been resolved in favor of a constructor:class B.(final int i) {
factory() => B.(42);
}The declaration in the body of
Bdeclares a factory constructor whose name isB(so you can invoke it usingB()), not a method whose name isfactory. If you have methods whose name isfactorythen the recommended way to avoid or fix the breakage is to add a return type (which makes it unambiguously a method).
factory() => ...; will work in both old language versions and the version that we release declaring constructors on, but have two different meanings.
Could we create a lint by this upcoming Dart version to move people away from writing factory()? If it's meant to be a method, they should write a return type, otherwise it'll be parsed as a factory constructor (soon).
cc. @bwilkerson