Skip to content

Commit afe69ed

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
Correct deprecated-use message for constructors
Change-Id: I9e8535a63ef9baeb741cb9f5d47015590b8031e7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292620 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 22a8877 commit afe69ed

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,12 @@ abstract class BaseDeprecatedMemberUseVerifier {
183183

184184
String displayName = element!.displayName;
185185
if (element is ConstructorElement) {
186-
// TODO(jwren) We should modify ConstructorElement.getDisplayName(),
186+
// TODO(jwren) We should modify ConstructorElement.displayName,
187187
// or have the logic centralized elsewhere, instead of doing this logic
188188
// here.
189-
displayName = element.enclosingElement.displayName;
190-
if (element.displayName.isNotEmpty) {
191-
displayName = "$displayName.${element.displayName}";
192-
}
189+
displayName = element.name == ''
190+
? '${element.displayName}.new'
191+
: element.displayName;
193192
} else if (element is LibraryElement) {
194193
displayName = element.definingCompilationUnit.source.uri.toString();
195194
} else if (node is MethodInvocation &&

pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,7 @@ f() {
795795
HintCode.DEPRECATED_MEMBER_USE,
796796
48,
797797
7,
798-
// TODO(srawlins): Fix this message!
799-
messageContains: ["'A.A.named' is deprecated and shouldn't be used."],
798+
messageContains: ["'A.named' is deprecated and shouldn't be used."],
800799
),
801800
],
802801
);
@@ -1429,7 +1428,8 @@ class B extends A {
14291428
}
14301429
''',
14311430
[
1432-
error(HintCode.DEPRECATED_MEMBER_USE, 57, 13),
1431+
error(HintCode.DEPRECATED_MEMBER_USE, 57, 13,
1432+
text: "'A.named' is deprecated and shouldn't be used."),
14331433
],
14341434
);
14351435
}
@@ -1449,8 +1449,7 @@ class B extends A {
14491449
''',
14501450
[
14511451
error(HintCode.DEPRECATED_MEMBER_USE, 57, 7,
1452-
// TODO(srawlins): Correct this message!
1453-
text: "'A.A' is deprecated and shouldn't be used."),
1452+
text: "'A.new' is deprecated and shouldn't be used."),
14541453
],
14551454
);
14561455
}

0 commit comments

Comments
 (0)