Fix missing identifier crash

* Also, fix missing quotes in message
* Also, do not report CLASS_INSTANTIATION_ACCESS_TO_UNKNOWN_MEMBER
  when obviously not a constructor name.

Fixes https://github.com/dart-lang/sdk/issues/50439

Change-Id: Idd78790289068bab1c20314d185a9abce1849ea2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/269202
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins
2022-11-11 06:01:30 +00:00
committed by Commit Queue
parent 020d53b059
commit bb0c4cede5
4 changed files with 30 additions and 5 deletions
@@ -695,7 +695,10 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
@override
DartObjectImpl? visitConstructorReference(ConstructorReference node) {
var constructorFunctionType = node.typeOrThrow as FunctionType;
var constructorFunctionType = node.typeOrThrow;
if (constructorFunctionType is! FunctionType) {
return null;
}
var classType = constructorFunctionType.returnType as InterfaceType;
var typeArguments = classType.typeArguments;
// The result is already instantiated during resolution;
+1 -1
View File
@@ -383,7 +383,7 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
static const CompileTimeErrorCode
CLASS_INSTANTIATION_ACCESS_TO_UNKNOWN_MEMBER = CompileTimeErrorCode(
'CLASS_INSTANTIATION_ACCESS_TO_MEMBER',
"The class '{0} doesn't have a constructor named '{1}.",
"The class '{0}' doesn't have a constructor named '{1}'.",
correctionMessage:
"Try invoking a different constructor, or defining a constructor named "
"'{1}'.",
+1 -1
View File
@@ -1548,7 +1548,7 @@ CompileTimeErrorCode:
0: the name of the member
CLASS_INSTANTIATION_ACCESS_TO_UNKNOWN_MEMBER:
sharedName: CLASS_INSTANTIATION_ACCESS_TO_MEMBER
problemMessage: "The class '{0} doesn't have a constructor named '{1}."
problemMessage: "The class '{0}' doesn't have a constructor named '{1}'."
correctionMessage: "Try invoking a different constructor, or defining a constructor named '{1}'."
comment: |-
Parameters:
+24 -2
View File
@@ -9,6 +9,7 @@ import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/constant.dart';
import 'package:analyzer/src/test_utilities/find_element.dart';
@@ -78,8 +79,8 @@ const x = kIsWeb ? a : b;
1),
]);
var x_result = findElement.topVar('x').evaluationResult;
assertDartObjectText(x_result.value, r'''
var result = findElement.topVar('x').evaluationResult;
assertDartObjectText(result.value, r'''
dynamic <unknown>
variable: self::@variable::x
''');
@@ -938,6 +939,27 @@ B<int>
''');
}
test_unknownConstuctor() async {
await assertErrorsInCode('''
class C<T> {
const C.named();
}
const x = C<int>.();
''', [
// TODO(https://github.com/dart-lang/sdk/issues/50441): This should not be
// reported.
error(CompileTimeErrorCode.CLASS_INSTANTIATION_ACCESS_TO_UNKNOWN_MEMBER,
45, 8),
error(ParserErrorCode.MISSING_IDENTIFIER, 52, 1),
]);
var result = findElement.topVar('x').evaluationResult;
assertDartObjectText(result.value, r'''
<null>
''');
}
test_variable_alias() async {
await resolveTestCode('''
const a = 42;