From 739826d041ddc2a72fd4c56a97d862a024eae264 Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Fri, 22 May 2026 12:53:51 -0700 Subject: [PATCH] Update ImportedElementsComputer for primary constructors This CL is to resolve a TODO. I couldn't find a way to trigger any bugs in the code, but I did add a test. I believe that the reason I couldn't trigger a bug is because any constructor that has a null `typeName` will not have a simple identifier in a place that would allow `_isConstructorDeclarationReturnType` to be invoked. I realized, while looking at the code, that the type check is unnecessary. If the type name is null, then the test will somply return `false`, which is what we'd expect it to do. Given that it isn't needed, I decided to remove it. Change-Id: Ib36aaf16475db0db5817e65a8b8bfbb8aa834dbd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505501 Reviewed-by: Samuel Rawlins Commit-Queue: Brian Wilkerson --- .../src/computer/imported_elements_computer.dart | 3 +-- .../computer/imported_elements_computer_test.dart | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart b/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart index 94c7f2b9563..d77ba4a1a0c 100644 --- a/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart +++ b/pkg/analysis_server/lib/src/computer/imported_elements_computer.dart @@ -148,7 +148,6 @@ class _Visitor extends UnifyingAstVisitor { static bool _isConstructorDeclarationReturnType(SimpleIdentifier node) { var parent = node.parent; - // TODO(scheglov): support primary constructors - return parent is ConstructorDeclaration && parent.typeName! == node; + return parent is ConstructorDeclaration && parent.typeName == node; } } diff --git a/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart b/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart index 2b337b9f612..a93bd626f3c 100644 --- a/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart +++ b/pkg/analysis_server/test/src/computer/imported_elements_computer_test.dart @@ -176,6 +176,19 @@ blankLine() { expect(importedElements, hasLength(0)); } + Future test_none_constructorDeclaration_withNew() async { + var content = ''' +[! +class A { + new (); + new named(); +} +!] +'''; + await _computeElements(content); + expect(importedElements, hasLength(0)); + } + Future test_none_constructorDeclarationReturnType() async { var content = ''' [!