[analyzer] Dot shorthands: Issue 61209 - Constant parameter mismatch error fix.

In the specific case where a dot shorthand is referencing a const constructor invocation of a imported class and the constructor has an optional parameter with a default value, the analyzer currently fails to compute the the constant result from that default value.

With the changes in this CL, we're properly calculating the dependencies we need to do that computation and prevent the `const_constructor_param_type_mismatch` error. We're missing a couple of visitors for the `DotShorthandConstructorInvocation` AST that tell the constant evaluator to evaluate its dependencies. This should work exactly like visiting `InstanceCreationExpression`s, in the same class.

Fixes: https://github.com/dart-lang/sdk/issues/61209
Bug: https://github.com/dart-lang/sdk/issues/59835
Change-Id: I6544e11e19f814b62108a736d1c778f8c4eda0cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446181
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
diff --git a/pkg/analyzer/lib/src/dart/constant/utilities.dart b/pkg/analyzer/lib/src/dart/constant/utilities.dart
index 03b3c56..2001e90 100644
--- a/pkg/analyzer/lib/src/dart/constant/utilities.dart
+++ b/pkg/analyzer/lib/src/dart/constant/utilities.dart
@@ -27,6 +27,17 @@
   }
 
   @override
+  void visitDotShorthandConstructorInvocation(
+    DotShorthandConstructorInvocation node,
+  ) {
+    if (node.isConst) {
+      _find(node);
+    } else {
+      super.visitDotShorthandConstructorInvocation(node);
+    }
+  }
+
+  @override
   void visitInstanceCreationExpression(InstanceCreationExpression node) {
     if (node.isConst) {
       _find(node);
@@ -222,6 +233,19 @@
   ReferenceFinder(this._callback);
 
   @override
+  void visitDotShorthandConstructorInvocation(
+    covariant DotShorthandConstructorInvocationImpl node,
+  ) {
+    if (node.isConst) {
+      var constructor = node.constructorName.element?.baseElement;
+      if (constructor is ConstructorElementImpl && constructor.isConst) {
+        _callback(constructor);
+      }
+    }
+    super.visitDotShorthandConstructorInvocation(node);
+  }
+
+  @override
   void visitInstanceCreationExpression(
     covariant InstanceCreationExpressionImpl node,
   ) {
diff --git a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
index be95cb6..1b3c80d 100644
--- a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
+++ b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart
@@ -6436,6 +6436,68 @@
 ''');
   }
 
+  test_dotShorthand_constructor_import_namedParameter() async {
+    newFile('$testPackageLibPath/a.dart', '''
+class C {
+  final int one;
+  const C({this.one = 1});
+}
+''');
+    await assertNoErrorsInCode('''
+import 'a.dart';
+const C c = .new();
+''');
+
+    var result = _topLevelVar('c');
+    assertDartObjectText(result, '''
+C
+  one: int 1
+  constructorInvocation
+    constructor: package:test/a.dart::@class::C::@constructor::new
+  variable: <testLibrary>::@topLevelVariable::c
+''');
+  }
+
+  test_dotShorthand_constructor_import_namedParameter_positional() async {
+    newFile('$testPackageLibPath/a.dart', '''
+class C {
+  final int one;
+  const C(int x, {this.one = 1});
+}
+''');
+    await assertNoErrorsInCode('''
+import 'a.dart';
+const C c = .new(1);
+''');
+
+    var result = _topLevelVar('c');
+    assertDartObjectText(result, '''
+C
+  one: int 1
+  constructorInvocation
+    constructor: package:test/a.dart::@class::C::@constructor::new
+    positionalArguments
+      0: int 1
+  variable: <testLibrary>::@topLevelVariable::c
+''');
+  }
+
+  test_dotShorthand_constructor_import_namedParameter_required() async {
+    newFile('$testPackageLibPath/a.dart', '''
+class C {
+  final int one;
+  const C({required this.one});
+}
+''');
+    await assertErrorsInCode(
+      '''
+import 'a.dart';
+const C c = .new();
+''',
+      [error(CompileTimeErrorCode.missingRequiredArgument, 30, 3)],
+    );
+  }
+
   test_dotShorthand_nonConstantArgument_issue60963() async {
     await assertErrorsInCode(
       '''