analyzer: Use new DiagnosticCode name in some directories

Work towards https://github.com/dart-lang/sdk/issues/60635

Change-Id: I942e690ab2946c564c10df228d17bd44de4ed375
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425406
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/diagnostic/diagnostic.dart b/pkg/analyzer/lib/diagnostic/diagnostic.dart
index d961453..5d92c30 100644
--- a/pkg/analyzer/lib/diagnostic/diagnostic.dart
+++ b/pkg/analyzer/lib/diagnostic/diagnostic.dart
@@ -16,8 +16,9 @@
 ///
 /// [guidelines]: https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/doc/implementation/diagnostics.md
 class Diagnostic {
-  /// The error code associated with the diagnostic.
-  final ErrorCode errorCode;
+  /// The diagnostic code associated with the diagnostic.
+  // TODO(srawlins): Rename this to `diagnosticCode`.
+  final DiagnosticCode errorCode;
 
   /// A list of messages that provide context for understanding the problem
   /// being reported. The list will be empty if there are no such messages.
diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart
index b957899..5b65fea 100644
--- a/pkg/analyzer/lib/error/error.dart
+++ b/pkg/analyzer/lib/error/error.dart
@@ -2,6 +2,9 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+/// @docImport 'package:analyzer/error/listener.dart';
+library;
+
 import 'dart:collection';
 
 import 'package:_fe_analyzer_shared/src/base/errors.dart';
@@ -21,30 +24,30 @@
 export 'package:analyzer/src/dart/error/lint_codes.dart' show LintCode;
 export 'package:analyzer/src/error/error_code_values.g.dart';
 
-/// The lazy initialized map from [ErrorCode.uniqueName] to the [ErrorCode]
-/// instance.
-final HashMap<String, ErrorCode> _uniqueNameToCodeMap =
+/// The lazy initialized map from [ErrorCode.uniqueName] to the
+/// [DiagnosticCode] instance.
+final HashMap<String, DiagnosticCode> _uniqueNameToCodeMap =
     _computeUniqueNameToCodeMap();
 
-/// Return the [ErrorCode] with the given [uniqueName], or `null` if not
+/// Return the [DiagnosticCode] with the given [uniqueName], or `null` if not
 /// found.
-ErrorCode? errorCodeByUniqueName(String uniqueName) {
+DiagnosticCode? errorCodeByUniqueName(String uniqueName) {
   return _uniqueNameToCodeMap[uniqueName];
 }
 
-/// Return the map from [ErrorCode.uniqueName] to the [ErrorCode] instance
+/// Return the map from [ErrorCode.uniqueName] to the [DiagnosticCode] instance
 /// for all [errorCodeValues].
-HashMap<String, ErrorCode> _computeUniqueNameToCodeMap() {
-  var result = HashMap<String, ErrorCode>();
-  for (ErrorCode errorCode in errorCodeValues) {
-    var uniqueName = errorCode.uniqueName;
+HashMap<String, DiagnosticCode> _computeUniqueNameToCodeMap() {
+  var result = HashMap<String, DiagnosticCode>();
+  for (DiagnosticCode diagnosticCode in errorCodeValues) {
+    var uniqueName = diagnosticCode.uniqueName;
     assert(() {
       if (result.containsKey(uniqueName)) {
         throw StateError('Not unique: $uniqueName');
       }
       return true;
     }());
-    result[uniqueName] = errorCode;
+    result[uniqueName] = diagnosticCode;
   }
   return result;
 }
diff --git a/pkg/analyzer/lib/error/listener.dart b/pkg/analyzer/lib/error/listener.dart
index 6155588..291e32e 100644
--- a/pkg/analyzer/lib/error/listener.dart
+++ b/pkg/analyzer/lib/error/listener.dart
@@ -69,7 +69,7 @@
   /// The location of the diagnostic will be the name of the [node].
   void atConstructorDeclaration(
     ConstructorDeclaration node,
-    ErrorCode errorCode, {
+    DiagnosticCode errorCode, {
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     Object? data,
@@ -95,7 +95,7 @@
   @experimental
   void atElement2(
     Element element2,
-    ErrorCode diagnosticCode, {
+    DiagnosticCode diagnosticCode, {
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     Object? data,
@@ -115,7 +115,7 @@
   /// The [entity] is used to compute the location of the error.
   void atEntity(
     SyntacticEntity entity,
-    ErrorCode errorCode, {
+    DiagnosticCode errorCode, {
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     Object? data,
@@ -134,7 +134,7 @@
   /// The [node] is used to compute the location of the error.
   void atNode(
     AstNode node,
-    ErrorCode diagnosticCode, {
+    DiagnosticCode diagnosticCode, {
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     Object? data,
@@ -154,7 +154,7 @@
   void atOffset({
     required int offset,
     required int length,
-    required ErrorCode errorCode,
+    required DiagnosticCode errorCode,
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     Object? data,
@@ -198,7 +198,7 @@
   /// The [span] is used to compute the location of the error.
   void atSourceSpan(
     SourceSpan span,
-    ErrorCode errorCode, {
+    DiagnosticCode errorCode, {
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     Object? data,
@@ -217,7 +217,7 @@
   /// used to compute the location of the error.
   void atToken(
     Token token,
-    ErrorCode diagnosticCode, {
+    DiagnosticCode diagnosticCode, {
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     Object? data,
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index dfb6be7..7741f53 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -2665,9 +2665,9 @@
 class ErrorEncoding {
   static AnalysisError? decode(Source source, AnalysisDriverUnitError error) {
     String errorName = error.uniqueName;
-    ErrorCode? errorCode =
+    DiagnosticCode? diagnosticCode =
         errorCodeByUniqueName(errorName) ?? _lintCodeByUniqueName(errorName);
-    if (errorCode == null) {
+    if (diagnosticCode == null) {
       // This could fail because the error code is no longer defined, or, in
       // the case of a lint rule, if the lint rule has been disabled since the
       // errors were written.
@@ -2695,7 +2695,7 @@
       source: source,
       offset: error.offset,
       length: error.length,
-      errorCode: errorCode,
+      errorCode: diagnosticCode,
       message: error.message,
       correctionMessage: error.correction.isEmpty ? null : error.correction,
       contextMessages: contextMessages,
@@ -2726,10 +2726,10 @@
     );
   }
 
-  /// Return the lint code with the given [errorName], or `null` if there is no
-  /// lint registered with that name.
-  static ErrorCode? _lintCodeByUniqueName(String errorName) {
-    return linter.Registry.ruleRegistry.codeForUniqueName(errorName);
+  /// Returns the lint code with the given [diagnosticName], or `null` if there
+  /// is no lint registered with that name.
+  static DiagnosticCode? _lintCodeByUniqueName(String diagnosticName) {
+    return linter.Registry.ruleRegistry.codeForUniqueName(diagnosticName);
   }
 }
 
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
index 44ef9d8..cf53d57 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
@@ -1003,11 +1003,15 @@
     directive?.element = partElement;
 
     void reportOnDirectiveUri(
-      ErrorCode errorCode, {
+      DiagnosticCode diagnosticCode, {
       List<Object>? arguments = const [],
     }) {
       if (directive != null) {
-        errorReporter.atNode(directive.uri, errorCode, arguments: arguments);
+        errorReporter.atNode(
+          directive.uri,
+          diagnosticCode,
+          arguments: arguments,
+        );
       }
     }
 
@@ -1036,15 +1040,15 @@
     var includedKind = includedFile.kind;
 
     if (includedKind is! PartFileKind) {
-      ErrorCode errorCode;
+      DiagnosticCode diagnosticCode;
       if (includedFile.exists) {
-        errorCode = CompileTimeErrorCode.PART_OF_NON_PART;
+        diagnosticCode = CompileTimeErrorCode.PART_OF_NON_PART;
       } else if (isGeneratedSource(includedFile.source)) {
-        errorCode = CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED;
+        diagnosticCode = CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED;
       } else {
-        errorCode = CompileTimeErrorCode.URI_DOES_NOT_EXIST;
+        diagnosticCode = CompileTimeErrorCode.URI_DOES_NOT_EXIST;
       }
-      reportOnDirectiveUri(errorCode, arguments: [includedFile.uriStr]);
+      reportOnDirectiveUri(diagnosticCode, arguments: [includedFile.uriStr]);
       return;
     }
 
diff --git a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
index 640c0ab..9f3a259 100644
--- a/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
+++ b/pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
@@ -292,7 +292,7 @@
               _errorReporter.atOffset(
                 offset: result.offset,
                 length: result.length,
-                errorCode: result.errorCode,
+                errorCode: result.diagnosticCode,
                 arguments: result.arguments,
                 contextMessages: result.contextMessages,
               );
@@ -315,7 +315,7 @@
       var elementType = nodeType.typeArguments[0];
       var verifier = _ConstLiteralVerifier(
         this,
-        errorCode: CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT,
+        diagnosticCode: CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT,
         listElementType: elementType,
       );
       for (var element in node.elements) {
@@ -414,7 +414,7 @@
         var config = _SetVerifierConfig(elementType: elementType);
         var verifier = _ConstLiteralVerifier(
           this,
-          errorCode: CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT,
+          diagnosticCode: CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT,
           setConfig: config,
         );
         for (CollectionElement element in node.elements) {
@@ -438,7 +438,7 @@
         var config = _MapVerifierConfig(keyType: keyType, valueType: valueType);
         var verifier = _ConstLiteralVerifier(
           this,
-          errorCode: CompileTimeErrorCode.NON_CONSTANT_MAP_ELEMENT,
+          diagnosticCode: CompileTimeErrorCode.NON_CONSTANT_MAP_ELEMENT,
           mapConfig: config,
         );
         for (var entry in node.elements) {
@@ -580,7 +580,7 @@
   /// See [CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS].
   void _checkForConstWithTypeParameters(
     TypeAnnotation type,
-    ErrorCode errorCode, {
+    DiagnosticCode diagnosticCode, {
     Set<TypeParameterElement>? allowedTypeParameters,
   }) {
     allowedTypeParameters = {...?allowedTypeParameters};
@@ -588,7 +588,7 @@
       // Should not be a type parameter.
       if (type.element2 is TypeParameterElement &&
           !allowedTypeParameters.contains(type.element2)) {
-        _errorReporter.atNode(type, errorCode);
+        _errorReporter.atNode(type, diagnosticCode);
         return;
       }
       // Check type arguments.
@@ -597,7 +597,7 @@
         for (var argument in typeArguments.arguments) {
           _checkForConstWithTypeParameters(
             argument,
-            errorCode,
+            diagnosticCode,
             allowedTypeParameters: allowedTypeParameters,
           );
         }
@@ -615,7 +615,7 @@
           if (bound != null) {
             _checkForConstWithTypeParameters(
               bound,
-              errorCode,
+              diagnosticCode,
               allowedTypeParameters: allowedTypeParameters,
             );
           }
@@ -625,7 +625,7 @@
       if (returnType != null) {
         _checkForConstWithTypeParameters(
           returnType,
-          errorCode,
+          diagnosticCode,
           allowedTypeParameters: allowedTypeParameters,
         );
       }
@@ -637,7 +637,7 @@
           if (parameterType != null) {
             _checkForConstWithTypeParameters(
               parameterType,
-              errorCode,
+              diagnosticCode,
               allowedTypeParameters: allowedTypeParameters,
             );
           }
@@ -650,9 +650,12 @@
   ///
   /// Returns the compile time constant of [expression], or an [InvalidConstant]
   /// if an error was found during evaluation. If an [InvalidConstant] was
-  /// found, the error will be reported and [errorCode] will be the default
+  /// found, the error will be reported and [diagnosticCode] will be the default
   /// error code to be reported.
-  Constant _evaluateAndReportError(Expression expression, ErrorCode errorCode) {
+  Constant _evaluateAndReportError(
+    Expression expression,
+    DiagnosticCode diagnosticCode,
+  ) {
     var errorListener = RecordingErrorListener();
     var subErrorReporter = ErrorReporter(errorListener, _errorReporter.source);
     var constantVisitor = ConstantVisitor(
@@ -662,16 +665,19 @@
     );
     var result = constantVisitor.evaluateConstant(expression);
     if (result is InvalidConstant) {
-      _reportError(result, errorCode);
+      _reportError(result, diagnosticCode);
     }
     return result;
   }
 
   /// Reports an error to the [_errorReporter].
   ///
-  /// If the [error] isn't found in the list, use the given [defaultErrorCode]
-  /// instead.
-  void _reportError(InvalidConstant error, ErrorCode? defaultErrorCode) {
+  /// If the [error] isn't found in the list, use the given
+  /// [defaultDiagnosticCode] instead.
+  void _reportError(
+    InvalidConstant error,
+    DiagnosticCode? defaultDiagnosticCode,
+  ) {
     if (error.avoidReporting) {
       return;
     }
@@ -681,127 +687,151 @@
     //
     // These error codes are more specific than the [defaultErrorCode] so they
     // will overwrite and replace the default when we report the error.
-    ErrorCode errorCode = error.errorCode;
+    DiagnosticCode diagnosticCode = error.diagnosticCode;
     if (identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.CONST_EVAL_EXTENSION_METHOD,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD,
         ) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT) ||
         identical(
-          errorCode,
+          diagnosticCode,
+          CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT,
+        ) ||
+        identical(
+          diagnosticCode,
           CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.CONST_EVAL_PRIMITIVE_EQUALITY,
         ) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS) ||
         identical(
-          errorCode,
+          diagnosticCode,
+          CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS,
+        ) ||
+        identical(
+          diagnosticCode,
           CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
         ) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE) ||
         identical(
-          errorCode,
+          diagnosticCode,
+          CompileTimeErrorCode.CONST_EVAL_THROWS_IDBZE,
+        ) ||
+        identical(
+          diagnosticCode,
           CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING,
         ) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_INT) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM_STRING) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_EVAL_TYPE_STRING) ||
+        identical(diagnosticCode, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL) ||
         identical(
-          errorCode,
+          diagnosticCode,
+          CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_INT,
+        ) ||
+        identical(diagnosticCode, CompileTimeErrorCode.CONST_EVAL_TYPE_INT) ||
+        identical(diagnosticCode, CompileTimeErrorCode.CONST_EVAL_TYPE_NUM) ||
+        identical(
+          diagnosticCode,
+          CompileTimeErrorCode.CONST_EVAL_TYPE_NUM_STRING,
+        ) ||
+        identical(
+          diagnosticCode,
+          CompileTimeErrorCode.CONST_EVAL_TYPE_STRING,
+        ) ||
+        identical(
+          diagnosticCode,
           CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
         ) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_TYPE_PARAMETER) ||
+        identical(diagnosticCode, CompileTimeErrorCode.CONST_TYPE_PARAMETER) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS_FUNCTION_TEAROFF,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.CONST_SPREAD_EXPECTED_LIST_OR_SET,
         ) ||
-        identical(errorCode, CompileTimeErrorCode.CONST_SPREAD_EXPECTED_MAP) ||
-        identical(errorCode, CompileTimeErrorCode.EXPRESSION_IN_MAP) ||
-        identical(errorCode, CompileTimeErrorCode.VARIABLE_TYPE_MISMATCH) ||
-        identical(errorCode, CompileTimeErrorCode.NON_BOOL_CONDITION) ||
         identical(
-          errorCode,
+          diagnosticCode,
+          CompileTimeErrorCode.CONST_SPREAD_EXPECTED_MAP,
+        ) ||
+        identical(diagnosticCode, CompileTimeErrorCode.EXPRESSION_IN_MAP) ||
+        identical(
+          diagnosticCode,
+          CompileTimeErrorCode.VARIABLE_TYPE_MISMATCH,
+        ) ||
+        identical(diagnosticCode, CompileTimeErrorCode.NON_BOOL_CONDITION) ||
+        identical(
+          diagnosticCode,
           CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.SET_ELEMENT_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.SPREAD_EXPRESSION_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode
               .NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode
               .INVALID_ANNOTATION_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode
               .CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.NON_CONSTANT_RECORD_FIELD_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode
               .CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.PATTERN_CONSTANT_FROM_DEFERRED_LIBRARY,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_FUNCTION,
         ) ||
         identical(
-          errorCode,
+          diagnosticCode,
           CompileTimeErrorCode
               .WRONG_NUMBER_OF_TYPE_ARGUMENTS_ANONYMOUS_FUNCTION,
         )) {
@@ -810,18 +840,18 @@
           source: _errorReporter.source,
           offset: error.offset,
           length: error.length,
-          errorCode: error.errorCode,
+          errorCode: error.diagnosticCode,
           arguments: error.arguments,
           contextMessages: error.contextMessages,
         ),
       );
-    } else if (defaultErrorCode != null) {
+    } else if (defaultDiagnosticCode != null) {
       _errorReporter.reportError(
         AnalysisError.tmp(
           source: _errorReporter.source,
           offset: error.offset,
           length: error.length,
-          errorCode: defaultErrorCode,
+          errorCode: defaultDiagnosticCode,
         ),
       );
     }
@@ -1160,14 +1190,14 @@
 
 class _ConstLiteralVerifier {
   final ConstantVerifier verifier;
-  final ErrorCode errorCode;
+  final DiagnosticCode diagnosticCode;
   final TypeImpl? listElementType;
   final _SetVerifierConfig? setConfig;
   final _MapVerifierConfig? mapConfig;
 
   _ConstLiteralVerifier(
     this.verifier, {
-    required this.errorCode,
+    required this.diagnosticCode,
     this.listElementType,
     this.mapConfig,
     this.setConfig,
@@ -1175,7 +1205,7 @@
 
   bool verify(CollectionElement element) {
     if (element is Expression) {
-      var value = verifier._evaluateAndReportError(element, errorCode);
+      var value = verifier._evaluateAndReportError(element, diagnosticCode);
       if (value is! DartObjectImpl) return false;
 
       var listElementType = this.listElementType;
@@ -1198,7 +1228,7 @@
     } else if (element is IfElement) {
       var conditionConstant = verifier._evaluateAndReportError(
         element.expression,
-        errorCode,
+        diagnosticCode,
       );
       if (conditionConstant is! DartObjectImpl) {
         return false;
@@ -1243,7 +1273,7 @@
     } else if (element is SpreadElement) {
       var value = verifier._evaluateAndReportError(
         element.expression,
-        errorCode,
+        diagnosticCode,
       );
       if (value is! DartObjectImpl) return false;
 
@@ -1258,7 +1288,10 @@
 
       return true;
     } else if (element is NullAwareElement) {
-      var value = verifier._evaluateAndReportError(element.value, errorCode);
+      var value = verifier._evaluateAndReportError(
+        element.value,
+        diagnosticCode,
+      );
       if (value is! DartObjectImpl) return false;
 
       var listElementType = this.listElementType;
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index f1dea67..8c68516 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -129,7 +129,7 @@
               )) {
                 constant.evaluationResult = InvalidConstant.forEntity(
                   entity: constantInitializer,
-                  errorCode: CompileTimeErrorCode.VARIABLE_TYPE_MISMATCH,
+                  diagnosticCode: CompileTimeErrorCode.VARIABLE_TYPE_MISMATCH,
                   arguments: [
                     dartConstant.type.getDisplayString(),
                     constant.type.getDisplayString(),
@@ -367,7 +367,7 @@
     // where the exception was found.
     if (result.isRuntimeException) {
       var formattedMessage = formatList(
-        result.errorCode.problemMessage,
+        result.diagnosticCode.problemMessage,
         result.arguments,
       );
       var contextMessage = DiagnosticMessageImpl(
@@ -380,7 +380,7 @@
       var errorNode = configuration.errorNode(node);
       result = InvalidConstant.forEntity(
         entity: errorNode,
-        errorCode: CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
+        diagnosticCode: CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
         contextMessages: [...result.contextMessages, contextMessage],
       );
     }
@@ -433,7 +433,7 @@
       );
       constant.evaluationResult = InvalidConstant.forElement(
         element: constant.asElement2!,
-        errorCode: CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT,
+        diagnosticCode: CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT,
       );
     } else if (constant is ConstructorFragmentImpl) {
       // We don't report cycle errors on constructor declarations here since
@@ -605,7 +605,7 @@
       _errorReporter.atOffset(
         offset: result.offset,
         length: result.length,
-        errorCode: result.errorCode,
+        errorCode: result.diagnosticCode,
         arguments: result.arguments,
         contextMessages: result.contextMessages,
       );
@@ -658,12 +658,12 @@
       case ExtensionElement():
         return InvalidConstant.forEntity(
           entity: node,
-          errorCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_METHOD,
+          diagnosticCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_METHOD,
         );
       case ExtensionTypeElement():
         return InvalidConstant.forEntity(
           entity: node,
-          errorCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD,
+          diagnosticCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD,
         );
     }
 
@@ -680,7 +680,7 @@
         case DartObjectImpl():
           return constant;
         case InvalidConstant():
-          throw EvaluationException(constant.errorCode);
+          throw EvaluationException(constant.diagnosticCode);
       }
     }
 
@@ -791,7 +791,7 @@
     if (!conditionConstant.isBool) {
       return InvalidConstant.forEntity(
         entity: condition,
-        errorCode: CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
+        diagnosticCode: CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL,
       );
     }
     conditionConstant = _dartObjectComputer.applyBooleanConversion(
@@ -834,7 +834,7 @@
     if (constructorFunctionType is! FunctionTypeImpl) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+        diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
       );
     }
     var classType = constructorFunctionType.returnType as InterfaceTypeImpl;
@@ -860,7 +860,7 @@
     if (constructorElement == null) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+        diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
       );
     }
 
@@ -895,7 +895,7 @@
     // problem - the error has already been reported.
     return InvalidConstant.forEntity(
       entity: node,
-      errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+      diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
     );
   }
 
@@ -944,7 +944,7 @@
         if (instantiatedTypeArgumentTypes.any(hasTypeParameterReference)) {
           return InvalidConstant.forEntity(
             entity: node,
-            errorCode:
+            diagnosticCode:
                 CompileTimeErrorCode
                     .CONST_WITH_TYPE_PARAMETERS_FUNCTION_TEAROFF,
           );
@@ -962,13 +962,13 @@
       var typeArgumentConstant = evaluateConstant(typeArgument);
       switch (typeArgumentConstant) {
         case InvalidConstant(
-          errorCode: CompileTimeErrorCode.CONST_TYPE_PARAMETER,
+          diagnosticCode: CompileTimeErrorCode.CONST_TYPE_PARAMETER,
         ):
           // If there's a type parameter error in the evaluated constant, we
           // convert the message to a more specific function reference error.
           return InvalidConstant.forEntity(
             entity: typeArgument,
-            errorCode:
+            diagnosticCode:
                 CompileTimeErrorCode
                     .CONST_WITH_TYPE_PARAMETERS_FUNCTION_TEAROFF,
           );
@@ -979,7 +979,7 @@
           if (typeArgumentType == null) {
             return InvalidConstant.forEntity(
               entity: typeArgument,
-              errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+              diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
             );
           }
           // TODO(srawlins): Test type alias types (`typedef i = int`) used as
@@ -1021,7 +1021,7 @@
       // TODO(kallentu): Use a better error code for this.
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+        diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
       );
     }
 
@@ -1061,7 +1061,7 @@
     if (!result.isBoolNumStringOrNull) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING,
+        diagnosticCode: CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING,
       );
     }
     return _dartObjectComputer.performToString(node, result);
@@ -1094,7 +1094,7 @@
     if (!node.isConst) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.MISSING_CONST_IN_LIST_LITERAL,
+        diagnosticCode: CompileTimeErrorCode.MISSING_CONST_IN_LIST_LITERAL,
       );
     }
     var nodeType = node.staticType;
@@ -1134,14 +1134,14 @@
     if (node.staticType is InvalidType) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+        diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
         isUnresolved: true,
       );
     }
 
     return InvalidConstant.forEntity(
       entity: node,
-      errorCode: CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION,
+      diagnosticCode: CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION,
     );
   }
 
@@ -1157,7 +1157,7 @@
         hasTypeParameterReference(type)) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.CONST_TYPE_PARAMETER,
+        diagnosticCode: CompileTimeErrorCode.CONST_TYPE_PARAMETER,
       );
     } else if (node.isDeferred) {
       return _getDeferredLibraryError(node, node.name2);
@@ -1238,12 +1238,12 @@
       case ExtensionElement():
         return InvalidConstant.forEntity(
           entity: node,
-          errorCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_METHOD,
+          diagnosticCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_METHOD,
         );
       case ExtensionTypeElement():
         return InvalidConstant.forEntity(
           entity: node,
-          errorCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD,
+          diagnosticCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD,
         );
     }
 
@@ -1362,7 +1362,7 @@
       if (!node.isConst) {
         return InvalidConstant.forEntity(
           entity: node,
-          errorCode: CompileTimeErrorCode.MISSING_CONST_IN_MAP_LITERAL,
+          diagnosticCode: CompileTimeErrorCode.MISSING_CONST_IN_MAP_LITERAL,
         );
       }
       var keyType = _typeProvider.dynamicType;
@@ -1390,7 +1390,7 @@
       if (!node.isConst) {
         return InvalidConstant.forEntity(
           entity: node,
-          errorCode: CompileTimeErrorCode.MISSING_CONST_IN_SET_LITERAL,
+          diagnosticCode: CompileTimeErrorCode.MISSING_CONST_IN_SET_LITERAL,
         );
       }
       var nodeType = node.staticType;
@@ -1478,7 +1478,7 @@
         case ForElement():
           return InvalidConstant.forEntity(
             entity: element,
-            errorCode: CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT,
+            diagnosticCode: CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT,
           );
         case IfElement():
           var condition = evaluateConstant(element.expression);
@@ -1500,7 +1500,7 @@
               if (conditionValue == null) {
                 return InvalidConstant.forEntity(
                   entity: element.expression,
-                  errorCode: CompileTimeErrorCode.NON_BOOL_CONDITION,
+                  diagnosticCode: CompileTimeErrorCode.NON_BOOL_CONDITION,
                 );
               } else if (conditionValue) {
                 branchResult = _buildListConstant(
@@ -1524,7 +1524,7 @@
         case MapLiteralEntry():
           return InvalidConstant.forEntity(
             entity: element,
-            errorCode: CompileTimeErrorCode.MAP_ENTRY_NOT_IN_MAP,
+            diagnosticCode: CompileTimeErrorCode.MAP_ENTRY_NOT_IN_MAP,
           );
         case SpreadElement():
           var spread = evaluateConstant(element.expression);
@@ -1540,7 +1540,7 @@
               if (listValue == null) {
                 return InvalidConstant.forEntity(
                   entity: element.expression,
-                  errorCode:
+                  diagnosticCode:
                       CompileTimeErrorCode.CONST_SPREAD_EXPECTED_LIST_OR_SET,
                 );
               }
@@ -1591,12 +1591,12 @@
         case Expression():
           return InvalidConstant.forEntity(
             entity: element,
-            errorCode: CompileTimeErrorCode.EXPRESSION_IN_MAP,
+            diagnosticCode: CompileTimeErrorCode.EXPRESSION_IN_MAP,
           );
         case ForElement():
           return InvalidConstant.forEntity(
             entity: element,
-            errorCode: CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT,
+            diagnosticCode: CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT,
           );
         case IfElement():
           var condition = evaluateConstant(element.expression);
@@ -1619,7 +1619,7 @@
               if (conditionValue == null) {
                 return InvalidConstant.forEntity(
                   entity: element.expression,
-                  errorCode: CompileTimeErrorCode.NON_BOOL_CONDITION,
+                  diagnosticCode: CompileTimeErrorCode.NON_BOOL_CONDITION,
                 );
               } else if (conditionValue) {
                 branchResult = _buildMapConstant(
@@ -1668,7 +1668,8 @@
               if (mapValue == null) {
                 return InvalidConstant.forEntity(
                   entity: element.expression,
-                  errorCode: CompileTimeErrorCode.CONST_SPREAD_EXPECTED_MAP,
+                  diagnosticCode:
+                      CompileTimeErrorCode.CONST_SPREAD_EXPECTED_MAP,
                 );
               }
               map.addAll(mapValue);
@@ -1678,7 +1679,7 @@
           // `CompileTimeErrorCode.NULL_AWARE_ELEMENT_IN_MAP`?
           return InvalidConstant.forEntity(
             entity: element,
-            errorCode: CompileTimeErrorCode.EXPRESSION_IN_MAP,
+            diagnosticCode: CompileTimeErrorCode.EXPRESSION_IN_MAP,
           );
       }
     }
@@ -1717,7 +1718,7 @@
         case ForElement():
           return InvalidConstant.forEntity(
             entity: element,
-            errorCode: CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT,
+            diagnosticCode: CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT,
           );
         case IfElement():
           var condition = evaluateConstant(element.expression);
@@ -1739,7 +1740,7 @@
               if (conditionValue == null) {
                 return InvalidConstant.forEntity(
                   entity: element.expression,
-                  errorCode: CompileTimeErrorCode.NON_BOOL_CONDITION,
+                  diagnosticCode: CompileTimeErrorCode.NON_BOOL_CONDITION,
                 );
               } else if (conditionValue) {
                 branchResult = _buildSetConstant(
@@ -1763,7 +1764,7 @@
         case MapLiteralEntry():
           return InvalidConstant.forEntity(
             entity: element,
-            errorCode: CompileTimeErrorCode.MAP_ENTRY_NOT_IN_MAP,
+            diagnosticCode: CompileTimeErrorCode.MAP_ENTRY_NOT_IN_MAP,
           );
         case SpreadElement():
           var spread = evaluateConstant(element.expression);
@@ -1779,7 +1780,7 @@
               if (setValue == null) {
                 return InvalidConstant.forEntity(
                   entity: element.expression,
-                  errorCode:
+                  diagnosticCode:
                       CompileTimeErrorCode.CONST_SPREAD_EXPECTED_LIST_OR_SET,
                 );
               }
@@ -1865,12 +1866,12 @@
       case ExtensionElement():
         return InvalidConstant.forEntity(
           entity: errorNode,
-          errorCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_METHOD,
+          diagnosticCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_METHOD,
         );
       case ExtensionTypeElement():
         return InvalidConstant.forEntity(
           entity: errorNode,
-          errorCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD,
+          diagnosticCode: CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD,
         );
     }
 
@@ -1891,7 +1892,7 @@
     // No other property access is allowed except for `.length` of a `String`.
     return InvalidConstant.forEntity(
       entity: errorNode,
-      errorCode: CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS,
+      diagnosticCode: CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS,
       arguments: [identifier.name, targetType.getDisplayString()],
     );
   }
@@ -1923,7 +1924,7 @@
             false)) {
       return InvalidConstant.forEntity(
         entity: expression,
-        errorCode: CompileTimeErrorCode.CONST_TYPE_PARAMETER,
+        diagnosticCode: CompileTimeErrorCode.CONST_TYPE_PARAMETER,
       );
     }
 
@@ -1949,7 +1950,7 @@
             if (identifier == null) {
               return InvalidConstant.forEntity(
                 entity: errorNode,
-                errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+                diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
               );
             }
             return _instantiateFunctionTypeForSimpleIdentifier(
@@ -1961,7 +1962,7 @@
             // if we remove `avoidReporting`.
             return InvalidConstant.forEntity(
               entity: errorNode,
-              errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+              diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
               avoidReporting: true,
               isUnresolved: true,
             );
@@ -1984,7 +1985,7 @@
         if (identifier == null) {
           return InvalidConstant.forEntity(
             entity: errorNode,
-            errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+            diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
           );
         }
         return _instantiateFunctionTypeForSimpleIdentifier(identifier, rawType);
@@ -2045,7 +2046,7 @@
         }
         return InvalidConstant.forEntity(
           entity: errorNode2,
-          errorCode: CompileTimeErrorCode.CONST_TYPE_PARAMETER,
+          diagnosticCode: CompileTimeErrorCode.CONST_TYPE_PARAMETER,
         );
       }
     }
@@ -2122,12 +2123,12 @@
     if (errorCode != null) {
       return InvalidConstant.forEntity(
         entity: errorTarget,
-        errorCode: errorCode,
+        diagnosticCode: errorCode,
       );
     }
     return InvalidConstant.forEntity(
       entity: node,
-      errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+      diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
     );
   }
 
@@ -2207,7 +2208,7 @@
     // Only report the first invalid constant we see.
     return InvalidConstant.forEntity(
       entity: notPotentiallyConstants.first,
-      errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+      diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
     );
   }
 
@@ -2224,7 +2225,7 @@
           _errorReporter.atOffset(
             offset: expressionValue.offset,
             length: expressionValue.length,
-            errorCode: expressionValue.errorCode,
+            errorCode: expressionValue.diagnosticCode,
             arguments: expressionValue.arguments,
             contextMessages: expressionValue.contextMessages,
           );
@@ -2257,7 +2258,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2274,7 +2275,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2285,7 +2286,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2300,7 +2301,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2315,7 +2316,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2330,7 +2331,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2345,7 +2346,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2360,7 +2361,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2375,7 +2376,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2390,7 +2391,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2405,7 +2406,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2420,7 +2421,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2435,7 +2436,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
         isRuntimeException: exception.isRuntimeException,
       );
     }
@@ -2451,7 +2452,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2466,7 +2467,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2481,7 +2482,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2507,7 +2508,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2522,7 +2523,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2533,7 +2534,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2548,7 +2549,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2563,7 +2564,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2574,7 +2575,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2589,7 +2590,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2600,7 +2601,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2615,7 +2616,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2630,7 +2631,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2645,7 +2646,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2656,7 +2657,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2671,7 +2672,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2688,7 +2689,7 @@
         if (node is SimpleIdentifier) {
           return InvalidConstant.forEntity(
             entity: typeArgumentsErrorNode,
-            errorCode:
+            diagnosticCode:
                 CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_FUNCTION,
             arguments: [
               node.name,
@@ -2699,7 +2700,7 @@
         }
         return InvalidConstant.forEntity(
           entity: typeArgumentsErrorNode,
-          errorCode:
+          diagnosticCode:
               CompileTimeErrorCode
                   .WRONG_NUMBER_OF_TYPE_ARGUMENTS_ANONYMOUS_FUNCTION,
           arguments: [rawType.typeFormals.length, typeArguments.length],
@@ -2710,7 +2711,7 @@
     } else {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+        diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
       );
     }
   }
@@ -2729,7 +2730,7 @@
     } on EvaluationException catch (exception) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: exception.errorCode,
+        diagnosticCode: exception.diagnosticCode,
       );
     }
   }
@@ -2873,7 +2874,7 @@
       if (!_checkFromEnvironmentArguments(arguments, definingType)) {
         return InvalidConstant.forEntity(
           entity: _errorNode,
-          errorCode: CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
+          diagnosticCode: CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
         );
       }
       String? variableName =
@@ -2915,7 +2916,7 @@
       if (!_checkSymbolArguments(arguments)) {
         return InvalidConstant.forEntity(
           entity: _errorNode,
-          errorCode: CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
+          diagnosticCode: CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
         );
       }
       return DartObjectImpl(
@@ -3040,7 +3041,7 @@
           var errorNode = field.constantInitializer ?? _errorNode;
           return InvalidConstant.forEntity(
             entity: errorNode,
-            errorCode:
+            diagnosticCode:
                 CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
             arguments: [
               fieldValue.type.getDisplayString(),
@@ -3118,7 +3119,8 @@
               return _InitializersEvaluationResult(
                 InvalidConstant.forEntity(
                   entity: _errorNode,
-                  errorCode: CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
+                  diagnosticCode:
+                      CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
                 ),
                 evaluationIsComplete: true,
               );
@@ -3131,7 +3133,8 @@
                 return _InitializersEvaluationResult(
                   InvalidConstant.forElement(
                     element: getter,
-                    errorCode: CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
+                    diagnosticCode:
+                        CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
                   ),
                   evaluationIsComplete: true,
                 );
@@ -3149,7 +3152,7 @@
                 return _InitializersEvaluationResult(
                   InvalidConstant.forEntity(
                     entity: errorNode,
-                    errorCode:
+                    diagnosticCode:
                         CompileTimeErrorCode
                             .CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
                     arguments: [
@@ -3238,7 +3241,7 @@
                   if (messageConstant.toStringValue() case var assertMessage?) {
                     invalidConstant = InvalidConstant.forEntity(
                       entity: initializer,
-                      errorCode:
+                      diagnosticCode:
                           CompileTimeErrorCode
                               .CONST_EVAL_ASSERTION_FAILURE_WITH_MESSAGE,
                       arguments: [assertMessage],
@@ -3250,7 +3253,8 @@
 
               invalidConstant ??= InvalidConstant.forEntity(
                 entity: initializer,
-                errorCode: CompileTimeErrorCode.CONST_EVAL_ASSERTION_FAILURE,
+                diagnosticCode:
+                    CompileTimeErrorCode.CONST_EVAL_ASSERTION_FAILURE,
                 isRuntimeException: true,
               );
               return _InitializersEvaluationResult(
@@ -3351,7 +3355,7 @@
               );
           return InvalidConstant.forEntity(
             entity: errorTarget,
-            errorCode:
+            diagnosticCode:
                 CompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
             arguments: [
               argumentValue.type.getDisplayString(),
@@ -3372,7 +3376,7 @@
                   !typeSystem.runtimeTypeMatch(argumentValue, fieldType)) {
                 return InvalidConstant.forEntity(
                   entity: errorTarget,
-                  errorCode:
+                  diagnosticCode:
                       CompileTimeErrorCode
                           .CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
                   arguments: [
@@ -3386,7 +3390,8 @@
             if (_fieldMap.containsKey(fieldName)) {
               return InvalidConstant.forEntity(
                 entity: _errorNode,
-                errorCode: CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
+                diagnosticCode:
+                    CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
               );
             }
             _fieldMap[fieldName] = argumentValue;
@@ -3540,13 +3545,13 @@
         if (newKeyword != null) {
           return InvalidConstant.forEntity(
             entity: newKeyword,
-            errorCode: CompileTimeErrorCode.CONST_WITH_NON_CONST,
+            diagnosticCode: CompileTimeErrorCode.CONST_WITH_NON_CONST,
           );
         }
       }
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.CONST_WITH_NON_CONST,
+        diagnosticCode: CompileTimeErrorCode.CONST_WITH_NON_CONST,
       );
     }
 
diff --git a/pkg/analyzer/lib/src/dart/constant/value.dart b/pkg/analyzer/lib/src/dart/constant/value.dart
index 3fa29c4..a0d8a88 100644
--- a/pkg/analyzer/lib/src/dart/constant/value.dart
+++ b/pkg/analyzer/lib/src/dart/constant/value.dart
@@ -1390,14 +1390,14 @@
 
 /// Exception that would be thrown during the evaluation of Dart code.
 class EvaluationException {
-  /// The error code associated with the exception.
-  final ErrorCode errorCode;
+  /// The diagnostic code associated with the exception.
+  final DiagnosticCode diagnosticCode;
 
   /// Returns `true` if the evaluation exception is a runtime exception.
   final bool isRuntimeException;
 
-  /// Initialize a newly created exception to have the given [errorCode].
-  EvaluationException(this.errorCode, {this.isRuntimeException = false});
+  /// Initialize a newly created exception to have the given [diagnosticCode].
+  EvaluationException(this.diagnosticCode, {this.isRuntimeException = false});
 }
 
 /// The state of an object representing a function.
@@ -2469,8 +2469,8 @@
   /// The length of the entity that the evaluation error is reported at.
   final int length;
 
-  /// The error code that is being reported.
-  final ErrorCode errorCode;
+  /// The diagnostic code that is being reported.
+  final DiagnosticCode diagnosticCode;
 
   /// The arguments required to complete the message.
   final List<Object> arguments;
@@ -2507,7 +2507,7 @@
   }) {
     return InvalidConstant.forEntity(
       entity: entity,
-      errorCode: other.errorCode,
+      diagnosticCode: other.diagnosticCode,
       arguments: other.arguments,
       contextMessages: other.contextMessages,
       avoidReporting: other.avoidReporting,
@@ -2519,7 +2519,7 @@
   /// Creates a constant evaluation error associated with an [element].
   InvalidConstant.forElement({
     required Element element,
-    required ErrorCode errorCode,
+    required DiagnosticCode diagnosticCode,
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     bool avoidReporting = false,
@@ -2528,7 +2528,7 @@
   }) : this._(
          length: element.name3!.length,
          offset: element.firstFragment.nameOffset2 ?? -1,
-         errorCode: errorCode,
+         diagnosticCode: diagnosticCode,
          arguments: arguments,
          contextMessages: contextMessages,
          avoidReporting: avoidReporting,
@@ -2540,7 +2540,7 @@
   /// [entity].
   InvalidConstant.forEntity({
     required SyntacticEntity entity,
-    required ErrorCode errorCode,
+    required DiagnosticCode diagnosticCode,
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     bool avoidReporting = false,
@@ -2549,7 +2549,7 @@
   }) : this._(
          offset: entity.offset,
          length: entity.length,
-         errorCode: errorCode,
+         diagnosticCode: diagnosticCode,
          arguments: arguments,
          contextMessages: contextMessages,
          avoidReporting: avoidReporting,
@@ -2569,13 +2569,13 @@
         parent2.isConst) {
       return InvalidConstant.forEntity(
         entity: node,
-        errorCode: CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT,
+        diagnosticCode: CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT,
         isUnresolved: isUnresolved,
       );
     }
     return InvalidConstant.forEntity(
       entity: node,
-      errorCode: CompileTimeErrorCode.INVALID_CONSTANT,
+      diagnosticCode: CompileTimeErrorCode.INVALID_CONSTANT,
       isUnresolved: isUnresolved,
     );
   }
@@ -2583,7 +2583,7 @@
   InvalidConstant._({
     required this.offset,
     required this.length,
-    required this.errorCode,
+    required this.diagnosticCode,
     List<Object>? arguments,
     List<DiagnosticMessage>? contextMessages,
     this.avoidReporting = false,
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 6020f5f..cc91bfe 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -1673,7 +1673,7 @@
           source: source,
           offset: evaluationResult.offset,
           length: evaluationResult.length,
-          errorCode: evaluationResult.errorCode,
+          errorCode: evaluationResult.diagnosticCode,
           arguments: evaluationResult.arguments,
           contextMessages: evaluationResult.contextMessages,
         ),
diff --git a/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart b/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
index 60c7885..832c9b5 100644
--- a/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
@@ -86,7 +86,7 @@
   TypeArgumentListImpl? get _typeArguments => node.typeArguments;
 
   @override
-  ErrorCode get _wrongNumberOfTypeArgumentsErrorCode =>
+  DiagnosticCode get _wrongNumberOfTypeArgumentsErrorCode =>
       CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
 
   @override
@@ -132,7 +132,7 @@
   TypeArgumentListImpl? get _typeArguments => node.typeArguments;
 
   @override
-  ErrorCode get _wrongNumberOfTypeArgumentsErrorCode =>
+  DiagnosticCode get _wrongNumberOfTypeArgumentsErrorCode =>
       CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
 }
 
@@ -213,7 +213,7 @@
 
   TypeArgumentListImpl? get _typeArguments;
 
-  ErrorCode get _wrongNumberOfTypeArgumentsErrorCode =>
+  DiagnosticCode get _wrongNumberOfTypeArgumentsErrorCode =>
       CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD;
 
   @override
diff --git a/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
index a89aaa7..83fdf65 100644
--- a/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/named_type_resolver.dart
@@ -466,27 +466,27 @@
       }
 
       // Report if this type is used as a class in hierarchy.
-      ErrorCode? errorCode;
+      DiagnosticCode? diagnosticCode;
       if (parent is ExtendsClause) {
-        errorCode =
+        diagnosticCode =
             CompileTimeErrorCode.EXTENDS_TYPE_ALIAS_EXPANDS_TO_TYPE_PARAMETER;
       } else if (parent is ImplementsClause) {
-        errorCode =
+        diagnosticCode =
             CompileTimeErrorCode
                 .IMPLEMENTS_TYPE_ALIAS_EXPANDS_TO_TYPE_PARAMETER;
       } else if (parent is MixinOnClause) {
-        errorCode =
+        diagnosticCode =
             CompileTimeErrorCode.MIXIN_ON_TYPE_ALIAS_EXPANDS_TO_TYPE_PARAMETER;
       } else if (parent is WithClause) {
-        errorCode =
+        diagnosticCode =
             CompileTimeErrorCode.MIXIN_OF_TYPE_ALIAS_EXPANDS_TO_TYPE_PARAMETER;
       }
-      if (errorCode != null) {
+      if (diagnosticCode != null) {
         var errorRange = _ErrorHelper._getErrorRange(node);
         errorReporter.atOffset(
           offset: errorRange.offset,
           length: errorRange.length,
-          errorCode: errorCode,
+          errorCode: diagnosticCode,
         );
         hasErrorReported = true;
         return InvalidTypeImpl.instance;
diff --git a/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart
index 9445354..86f5a03 100644
--- a/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart
@@ -424,7 +424,7 @@
 
   void _reportUnresolvedIndex(
     IndexExpression node,
-    ErrorCode errorCode, [
+    DiagnosticCode diagnosticCode, [
     List<Object> arguments = const [],
   ]) {
     var leftBracket = node.leftBracket;
@@ -435,7 +435,7 @@
     errorReporter.atOffset(
       offset: offset,
       length: length,
-      errorCode: errorCode,
+      errorCode: diagnosticCode,
       arguments: arguments,
     );
   }
diff --git a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart
index c935e6c..8aca56d 100644
--- a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart
@@ -1722,30 +1722,30 @@
       return;
     }
 
-    ErrorCode? errorCode;
+    DiagnosticCode? diagnosticCode;
     switch (clause) {
       case null:
         if (declaration is ClassTypeAlias) {
-          errorCode = CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS;
+          diagnosticCode = CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS;
         }
       case ExtendsClause():
         if (declaration is ClassDeclaration) {
-          errorCode =
+          diagnosticCode =
               declaration.withClause == null
                   ? CompileTimeErrorCode.EXTENDS_NON_CLASS
                   : CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS;
         }
       case ImplementsClause():
-        errorCode = CompileTimeErrorCode.IMPLEMENTS_NON_CLASS;
+        diagnosticCode = CompileTimeErrorCode.IMPLEMENTS_NON_CLASS;
       case MixinOnClause():
-        errorCode =
+        diagnosticCode =
             CompileTimeErrorCode.MIXIN_SUPER_CLASS_CONSTRAINT_NON_INTERFACE;
       case WithClause():
-        errorCode = CompileTimeErrorCode.MIXIN_OF_NON_CLASS;
+        diagnosticCode = CompileTimeErrorCode.MIXIN_OF_NON_CLASS;
     }
 
     // Should not happen.
-    if (errorCode == null) {
+    if (diagnosticCode == null) {
       assert(false);
       return;
     }
@@ -1756,7 +1756,7 @@
     _errorReporter.atOffset(
       offset: offset,
       length: length,
-      errorCode: errorCode,
+      errorCode: diagnosticCode,
     );
   }