Skip to content

Commit 82fb939

Browse files
bwilkersonCommit Queue
authored andcommitted
Add documentation for the deprecated_factory_method warning
Change-Id: If215a7b2d2faebe3959831837077c370509e9399 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467220 Reviewed-by: Connie Ooi <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 30f5c88 commit 82fb939

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

pkg/analyzer/messages.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25335,6 +25335,49 @@ WarningCode:
2533525335
problemMessage: Methods named 'factory' will become constructors when the primary_constructors feature is enabled.
2533625336
correctionMessage: Try adding a return type or modifier before the method's name, or change the name of the method.
2533725337
hasPublishedDocs: false
25338+
documentation: |-
25339+
#### Description
25340+
25341+
The analyzer produces this diagnostic when the declaration of an instance
25342+
method named `factory` is interpreted as a constructor declaration after
25343+
the `primary_constructors` feature is enabled.
25344+
25345+
This issue only affects declarations that lack a return type and where the
25346+
method name is the first token or is preceded only by `external`,
25347+
`augment`, or `augment external`. The `augment` and `augment external`
25348+
keywords are valid only after the augmentations feature is enabled.
25349+
25350+
#### Example
25351+
25352+
The following code produces this diagnostic because the instance method
25353+
named `factory` has no return type or modifiers:
25354+
25355+
```dart
25356+
// @dart=3.10
25357+
class C {
25358+
[!factory!]() => C();
25359+
}
25360+
```
25361+
25362+
#### Common fixes
25363+
25364+
If the name can be changed, then rename the method:
25365+
25366+
```dart
25367+
// @dart=3.10
25368+
class C {
25369+
make() => C();
25370+
}
25371+
```
25372+
25373+
If the name must remain `factory`, then add a return type:
25374+
25375+
```dart
25376+
// @dart=3.10
25377+
class C {
25378+
C factory() => C();
25379+
}
25380+
```
2533825381
deprecatedImplement:
2533925382
type: staticWarning
2534025383
parameters:

0 commit comments

Comments
 (0)