Augment. Report positional / optional / named formal parameters shape mismatch.
Change-Id: Ia218cc02024a0a12f35a9c8fdba8b1e65f691244 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509161 Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
@@ -245,10 +245,18 @@ augmentation_modifier_extra:
|
||||
status: hasFix
|
||||
augmentation_modifier_missing:
|
||||
status: needsFix
|
||||
augmentation_named_formal_parameter_extra:
|
||||
status: needsEvaluation
|
||||
augmentation_named_formal_parameter_missing:
|
||||
status: needsEvaluation
|
||||
augmentation_of_different_declaration_kind:
|
||||
status: noFix
|
||||
augmentation_of_mixin_application_class:
|
||||
status: needsEvaluation
|
||||
augmentation_optional_positional_formal_parameter_count:
|
||||
status: needsEvaluation
|
||||
augmentation_required_positional_formal_parameter_count:
|
||||
status: needsEvaluation
|
||||
augmentation_return_type_mismatch:
|
||||
status: needsEvaluation
|
||||
augmentation_type_parameter_bound:
|
||||
|
||||
@@ -976,6 +976,44 @@ augmentationModifierMissing = DiagnosticWithArguments(
|
||||
expectedTypes: [ExpectedType.string],
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// String name: the name of the formal parameter.
|
||||
const DiagnosticWithArguments<
|
||||
LocatableDiagnostic Function({required String name})
|
||||
>
|
||||
augmentationNamedFormalParameterExtra = DiagnosticWithArguments(
|
||||
name: 'augmentation_named_formal_parameter_extra',
|
||||
problemMessage:
|
||||
"The augmentation has a named formal parameter '{0}', but the declaration "
|
||||
"doesn't.",
|
||||
correctionMessage:
|
||||
"Try changing the augmentation's formal parameters to match the "
|
||||
"declaration.",
|
||||
type: DiagnosticType.COMPILE_TIME_ERROR,
|
||||
uniqueName: 'augmentation_named_formal_parameter_extra',
|
||||
withArguments: _withArgumentsAugmentationNamedFormalParameterExtra,
|
||||
expectedTypes: [ExpectedType.string],
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// String name: the name of the formal parameter.
|
||||
const DiagnosticWithArguments<
|
||||
LocatableDiagnostic Function({required String name})
|
||||
>
|
||||
augmentationNamedFormalParameterMissing = DiagnosticWithArguments(
|
||||
name: 'augmentation_named_formal_parameter_missing',
|
||||
problemMessage:
|
||||
"The augmentation is missing the named formal parameter '{0}' from the "
|
||||
"declaration.",
|
||||
correctionMessage:
|
||||
"Try changing the augmentation's formal parameters to match the "
|
||||
"declaration.",
|
||||
type: DiagnosticType.COMPILE_TIME_ERROR,
|
||||
uniqueName: 'augmentation_named_formal_parameter_missing',
|
||||
withArguments: _withArgumentsAugmentationNamedFormalParameterMissing,
|
||||
expectedTypes: [ExpectedType.string],
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// String declarationKind: the name of the declaration kind.
|
||||
/// String augmentationKind: the name of the augmentation kind.
|
||||
@@ -1009,6 +1047,58 @@ const DiagnosticWithoutArguments augmentationOfMixinApplicationClass =
|
||||
expectedTypes: [],
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// int expectedCount: the number of optional positional formal parameters in
|
||||
/// the declaration.
|
||||
/// int actualCount: the number of optional positional formal parameters in
|
||||
/// the augmentation.
|
||||
const DiagnosticWithArguments<
|
||||
LocatableDiagnostic Function({
|
||||
required int expectedCount,
|
||||
required int actualCount,
|
||||
})
|
||||
>
|
||||
augmentationOptionalPositionalFormalParameterCount = DiagnosticWithArguments(
|
||||
name: 'augmentation_optional_positional_formal_parameter_count',
|
||||
problemMessage:
|
||||
"The augmentation has {1} optional positional formal parameters, but the "
|
||||
"declaration has {0}.",
|
||||
correctionMessage:
|
||||
"Try changing the augmentation's formal parameters to match the "
|
||||
"declaration.",
|
||||
type: DiagnosticType.COMPILE_TIME_ERROR,
|
||||
uniqueName: 'augmentation_optional_positional_formal_parameter_count',
|
||||
withArguments:
|
||||
_withArgumentsAugmentationOptionalPositionalFormalParameterCount,
|
||||
expectedTypes: [ExpectedType.int, ExpectedType.int],
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// int expectedCount: the number of required positional formal parameters in
|
||||
/// the declaration.
|
||||
/// int actualCount: the number of required positional formal parameters in
|
||||
/// the augmentation.
|
||||
const DiagnosticWithArguments<
|
||||
LocatableDiagnostic Function({
|
||||
required int expectedCount,
|
||||
required int actualCount,
|
||||
})
|
||||
>
|
||||
augmentationRequiredPositionalFormalParameterCount = DiagnosticWithArguments(
|
||||
name: 'augmentation_required_positional_formal_parameter_count',
|
||||
problemMessage:
|
||||
"The augmentation has {1} required positional formal parameters, but the "
|
||||
"declaration has {0}.",
|
||||
correctionMessage:
|
||||
"Try changing the augmentation's formal parameters to match the "
|
||||
"declaration.",
|
||||
type: DiagnosticType.COMPILE_TIME_ERROR,
|
||||
uniqueName: 'augmentation_required_positional_formal_parameter_count',
|
||||
withArguments:
|
||||
_withArgumentsAugmentationRequiredPositionalFormalParameterCount,
|
||||
expectedTypes: [ExpectedType.int, ExpectedType.int],
|
||||
);
|
||||
|
||||
/// Parameters:
|
||||
/// Type expectedType: the return type of the declaration
|
||||
/// Type actualType: the return type of the augmentation
|
||||
@@ -18612,6 +18702,22 @@ LocatableDiagnostic _withArgumentsAugmentationModifierMissing({
|
||||
return LocatableDiagnosticImpl(diag.augmentationModifierMissing, [modifier]);
|
||||
}
|
||||
|
||||
LocatableDiagnostic _withArgumentsAugmentationNamedFormalParameterExtra({
|
||||
required String name,
|
||||
}) {
|
||||
return LocatableDiagnosticImpl(diag.augmentationNamedFormalParameterExtra, [
|
||||
name,
|
||||
]);
|
||||
}
|
||||
|
||||
LocatableDiagnostic _withArgumentsAugmentationNamedFormalParameterMissing({
|
||||
required String name,
|
||||
}) {
|
||||
return LocatableDiagnosticImpl(diag.augmentationNamedFormalParameterMissing, [
|
||||
name,
|
||||
]);
|
||||
}
|
||||
|
||||
LocatableDiagnostic _withArgumentsAugmentationOfDifferentDeclarationKind({
|
||||
required String declarationKind,
|
||||
required String augmentationKind,
|
||||
@@ -18622,6 +18728,28 @@ LocatableDiagnostic _withArgumentsAugmentationOfDifferentDeclarationKind({
|
||||
]);
|
||||
}
|
||||
|
||||
LocatableDiagnostic
|
||||
_withArgumentsAugmentationOptionalPositionalFormalParameterCount({
|
||||
required int expectedCount,
|
||||
required int actualCount,
|
||||
}) {
|
||||
return LocatableDiagnosticImpl(
|
||||
diag.augmentationOptionalPositionalFormalParameterCount,
|
||||
[expectedCount, actualCount],
|
||||
);
|
||||
}
|
||||
|
||||
LocatableDiagnostic
|
||||
_withArgumentsAugmentationRequiredPositionalFormalParameterCount({
|
||||
required int expectedCount,
|
||||
required int actualCount,
|
||||
}) {
|
||||
return LocatableDiagnosticImpl(
|
||||
diag.augmentationRequiredPositionalFormalParameterCount,
|
||||
[expectedCount, actualCount],
|
||||
);
|
||||
}
|
||||
|
||||
LocatableDiagnostic _withArgumentsAugmentationReturnTypeMismatch({
|
||||
required DartType expectedType,
|
||||
required DartType actualType,
|
||||
|
||||
@@ -75,8 +75,12 @@ const List<DiagnosticCode> diagnosticCodeValues = [
|
||||
diag.augmentationInducedSetterAlreadyComplete,
|
||||
diag.augmentationModifierExtra,
|
||||
diag.augmentationModifierMissing,
|
||||
diag.augmentationNamedFormalParameterExtra,
|
||||
diag.augmentationNamedFormalParameterMissing,
|
||||
diag.augmentationOfDifferentDeclarationKind,
|
||||
diag.augmentationOfMixinApplicationClass,
|
||||
diag.augmentationOptionalPositionalFormalParameterCount,
|
||||
diag.augmentationRequiredPositionalFormalParameterCount,
|
||||
diag.augmentationReturnTypeMismatch,
|
||||
diag.augmentationTypeParameterBound,
|
||||
diag.augmentationTypeParameterCount,
|
||||
|
||||
@@ -670,6 +670,10 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
||||
var element = fragment.element;
|
||||
|
||||
_checkAugmentationWithoutDeclaration(node.augmentKeyword, fragment);
|
||||
_checkForAugmentationFormalParameters(
|
||||
executableFragment: fragment,
|
||||
formalParameterList: node.parameters,
|
||||
);
|
||||
|
||||
if (fragment.isAugmentation && fragment.isComplete) {
|
||||
var precedingComplete = fragment.nearestPrecedingCompleteFragment;
|
||||
@@ -1216,6 +1220,12 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
||||
returnTypeNode: node.returnType,
|
||||
errorEntity: node.returnType ?? node.name,
|
||||
);
|
||||
if (node.functionExpression.parameters case var parameters?) {
|
||||
_checkForAugmentationFormalParameters(
|
||||
executableFragment: fragment,
|
||||
formalParameterList: parameters,
|
||||
);
|
||||
}
|
||||
|
||||
if (element.enclosingElement is! LibraryElement) {
|
||||
_hiddenElements!.declare(element);
|
||||
@@ -1484,6 +1494,12 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
||||
returnTypeNode: node.returnType,
|
||||
errorEntity: node.returnType ?? node.name,
|
||||
);
|
||||
if (node.parameters case var parameters?) {
|
||||
_checkForAugmentationFormalParameters(
|
||||
executableFragment: fragment,
|
||||
formalParameterList: parameters,
|
||||
);
|
||||
}
|
||||
|
||||
_withEnclosingExecutable(
|
||||
element,
|
||||
@@ -2743,6 +2759,176 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
||||
}
|
||||
}
|
||||
|
||||
void _checkForAugmentationFormalParameters({
|
||||
required ExecutableFragmentImpl executableFragment,
|
||||
required FormalParameterList formalParameterList,
|
||||
}) {
|
||||
if (!executableFragment.isAugmentation) {
|
||||
return;
|
||||
}
|
||||
|
||||
var firstExecutableFragment = executableFragment.element.firstFragment;
|
||||
if (identical(executableFragment, firstExecutableFragment) ||
|
||||
firstExecutableFragment.isAugmentation) {
|
||||
return;
|
||||
}
|
||||
|
||||
var firstParameters = firstExecutableFragment.formalParameters
|
||||
.where((parameter) => !parameter.isOriginOtherFragmentOfEnclosing)
|
||||
.toList();
|
||||
var currentParameters = executableFragment.formalParameters
|
||||
.where((parameter) => !parameter.isOriginOtherFragmentOfEnclosing)
|
||||
.toList();
|
||||
|
||||
var firstExecutableContextMessages = [
|
||||
?firstExecutableFragment.contextMessageAt(
|
||||
'The declaration being augmented.',
|
||||
),
|
||||
];
|
||||
|
||||
var firstRequiredPositionalCount = firstParameters
|
||||
.where((parameter) => parameter.isRequiredPositional)
|
||||
.length;
|
||||
var currentRequiredPositionalCount = currentParameters
|
||||
.where((parameter) => parameter.isRequiredPositional)
|
||||
.length;
|
||||
|
||||
FormalParameter? formalParameterAtPositionalIndex(int index) {
|
||||
return formalParameterList.parameters
|
||||
.where((parameter) => parameter.isPositional)
|
||||
.elementAtOrNull(index);
|
||||
}
|
||||
|
||||
SyntacticEntity formalParameterErrorEntity(FormalParameter? parameter) {
|
||||
if (parameter == null) {
|
||||
return formalParameterList.rightParenthesis;
|
||||
}
|
||||
return parameter.name ?? parameter;
|
||||
}
|
||||
|
||||
if (currentRequiredPositionalCount < firstRequiredPositionalCount) {
|
||||
diagnosticReporter.report(
|
||||
diag.augmentationRequiredPositionalFormalParameterCount
|
||||
.withArguments(
|
||||
expectedCount: firstRequiredPositionalCount,
|
||||
actualCount: currentRequiredPositionalCount,
|
||||
)
|
||||
.withContextMessages(firstExecutableContextMessages)
|
||||
.at(
|
||||
formalParameterList.leftDelimiter ??
|
||||
formalParameterErrorEntity(
|
||||
formalParameterAtPositionalIndex(
|
||||
currentRequiredPositionalCount,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (currentRequiredPositionalCount > firstRequiredPositionalCount) {
|
||||
diagnosticReporter.report(
|
||||
diag.augmentationRequiredPositionalFormalParameterCount
|
||||
.withArguments(
|
||||
expectedCount: firstRequiredPositionalCount,
|
||||
actualCount: currentRequiredPositionalCount,
|
||||
)
|
||||
.withContextMessages(firstExecutableContextMessages)
|
||||
.at(
|
||||
formalParameterErrorEntity(
|
||||
formalParameterAtPositionalIndex(firstRequiredPositionalCount),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
var firstOptionalPositionalCount = firstParameters
|
||||
.where((parameter) => parameter.isOptionalPositional)
|
||||
.length;
|
||||
var currentOptionalPositionalCount = currentParameters
|
||||
.where((parameter) => parameter.isOptionalPositional)
|
||||
.length;
|
||||
|
||||
if (currentOptionalPositionalCount < firstOptionalPositionalCount) {
|
||||
diagnosticReporter.report(
|
||||
diag.augmentationOptionalPositionalFormalParameterCount
|
||||
.withArguments(
|
||||
expectedCount: firstOptionalPositionalCount,
|
||||
actualCount: currentOptionalPositionalCount,
|
||||
)
|
||||
.withContextMessages(firstExecutableContextMessages)
|
||||
.at(formalParameterList.rightParenthesis),
|
||||
);
|
||||
} else if (currentOptionalPositionalCount >
|
||||
firstOptionalPositionalCount) {
|
||||
diagnosticReporter.report(
|
||||
diag.augmentationOptionalPositionalFormalParameterCount
|
||||
.withArguments(
|
||||
expectedCount: firstOptionalPositionalCount,
|
||||
actualCount: currentOptionalPositionalCount,
|
||||
)
|
||||
.withContextMessages(firstExecutableContextMessages)
|
||||
.at(
|
||||
firstOptionalPositionalCount == 0
|
||||
? formalParameterList.leftDelimiter ??
|
||||
formalParameterErrorEntity(
|
||||
formalParameterAtPositionalIndex(
|
||||
firstRequiredPositionalCount,
|
||||
),
|
||||
)
|
||||
: formalParameterErrorEntity(
|
||||
formalParameterAtPositionalIndex(
|
||||
firstRequiredPositionalCount +
|
||||
firstOptionalPositionalCount,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var firstNamedParametersByName = <String, FormalParameterFragmentImpl>{};
|
||||
for (var parameter in firstParameters) {
|
||||
var name = parameter.name;
|
||||
if (parameter.isNamed && name != null) {
|
||||
firstNamedParametersByName[name] = parameter;
|
||||
}
|
||||
}
|
||||
|
||||
var currentNamedParametersByName = <String, FormalParameter>{};
|
||||
for (var formalParameter in formalParameterList.parameters) {
|
||||
var parameter = formalParameter.declaredFragment;
|
||||
if (parameter is FormalParameterFragmentImpl && parameter.isNamed) {
|
||||
var name = parameter.name;
|
||||
if (name != null) {
|
||||
currentNamedParametersByName.putIfAbsent(name, () => formalParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var entry in currentNamedParametersByName.entries) {
|
||||
var name = entry.key;
|
||||
if (!firstNamedParametersByName.containsKey(name)) {
|
||||
diagnosticReporter.report(
|
||||
diag.augmentationNamedFormalParameterExtra
|
||||
.withArguments(name: name)
|
||||
.withContextMessages(firstExecutableContextMessages)
|
||||
.at(formalParameterErrorEntity(entry.value)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (var entry in firstNamedParametersByName.entries) {
|
||||
var name = entry.key;
|
||||
if (!currentNamedParametersByName.containsKey(name)) {
|
||||
diagnosticReporter.report(
|
||||
diag.augmentationNamedFormalParameterMissing
|
||||
.withArguments(name: name)
|
||||
.withContextMessages([
|
||||
?entry.value.contextMessageAt('The formal parameter is here.'),
|
||||
])
|
||||
.at(formalParameterList.rightParenthesis),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _checkForAugmentationInducedAccessorsAlreadyComplete({
|
||||
required Token errorToken,
|
||||
required PropertyInducingFragmentImpl fragment,
|
||||
|
||||
@@ -1832,6 +1832,31 @@ CompileTimeErrorCode:
|
||||
problemMessage: The augmentation is missing the '#modifier' modifier that the declaration has.
|
||||
correctionMessage: Try adding the '#modifier' modifier, or removing it from the declaration.
|
||||
hasPublishedDocs: false
|
||||
augmentationNamedFormalParameterExtra:
|
||||
type: compileTimeError
|
||||
parameters:
|
||||
String name: the name of the formal parameter.
|
||||
experiment: augmentations
|
||||
problemMessage: "The augmentation has a named formal parameter '#name', but the declaration doesn't."
|
||||
correctionMessage: Try changing the augmentation's formal parameters to match the declaration.
|
||||
hasPublishedDocs: false
|
||||
augmentationNamedFormalParameterMissing:
|
||||
type: compileTimeError
|
||||
parameters:
|
||||
String name: the name of the formal parameter.
|
||||
experiment: augmentations
|
||||
problemMessage: "The augmentation is missing the named formal parameter '#name' from the declaration."
|
||||
correctionMessage: Try changing the augmentation's formal parameters to match the declaration.
|
||||
hasPublishedDocs: false
|
||||
augmentationOptionalPositionalFormalParameterCount:
|
||||
type: compileTimeError
|
||||
parameters:
|
||||
int expectedCount: the number of optional positional formal parameters in the declaration.
|
||||
int actualCount: the number of optional positional formal parameters in the augmentation.
|
||||
experiment: augmentations
|
||||
problemMessage: "The augmentation has #actualCount optional positional formal parameters, but the declaration has #expectedCount."
|
||||
correctionMessage: Try changing the augmentation's formal parameters to match the declaration.
|
||||
hasPublishedDocs: false
|
||||
augmentationOfDifferentDeclarationKind:
|
||||
type: compileTimeError
|
||||
parameters:
|
||||
@@ -1894,6 +1919,15 @@ CompileTimeErrorCode:
|
||||
problemMessage: "Mixin application classes can't be augmented."
|
||||
correctionMessage: Try removing the 'augment' keyword, or making the target a normal class.
|
||||
hasPublishedDocs: false
|
||||
augmentationRequiredPositionalFormalParameterCount:
|
||||
type: compileTimeError
|
||||
parameters:
|
||||
int expectedCount: the number of required positional formal parameters in the declaration.
|
||||
int actualCount: the number of required positional formal parameters in the augmentation.
|
||||
experiment: augmentations
|
||||
problemMessage: "The augmentation has #actualCount required positional formal parameters, but the declaration has #expectedCount."
|
||||
correctionMessage: Try changing the augmentation's formal parameters to match the declaration.
|
||||
hasPublishedDocs: false
|
||||
augmentationInducedGetterReturnTypeMismatch:
|
||||
type: compileTimeError
|
||||
parameters:
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
|
||||
// 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.
|
||||
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
import '../dart/resolution/node_text_expectations.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(AugmentationFormalParameterShapeTest);
|
||||
defineReflectiveTests(UpdateNodeTextExpectations);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AugmentationFormalParameterShapeTest extends PubPackageResolutionTest {
|
||||
test_class_constructor_rP1__rP1_rP2() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
A._();
|
||||
factory A(int? p1);
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment factory A(int? p1, int? p2) => A._();
|
||||
// ^^
|
||||
// [diag.augmentationRequiredPositionalFormalParameterCount][context 1] The augmentation has 2 required positional formal parameters, but the declaration has 1.
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_instanceField_inducedSetter_rP1__rP1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
class A {
|
||||
int foo = 0;
|
||||
augment void set foo(int p1);
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_instanceMethod_rP1__rP1_rP2() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
void foo(int? p1);
|
||||
// ^^^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void foo(int? p1, int? p2) {}
|
||||
// ^^
|
||||
// [diag.augmentationRequiredPositionalFormalParameterCount][context 1] The augmentation has 2 required positional formal parameters, but the declaration has 1.
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_class_instanceSetter_rP1__rP1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
abstract class A {
|
||||
set foo(int? p1);
|
||||
augment set foo(int? p1) {}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rn1__none() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({int? n1});
|
||||
// ^^
|
||||
// [context 1] The formal parameter is here.
|
||||
augment void f() {}
|
||||
// ^
|
||||
// [diag.augmentationNamedFormalParameterMissing][context 1] The augmentation is missing the named formal parameter 'n1' from the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rn1__none__rn1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({int? n1});
|
||||
// ^^
|
||||
// [context 1] The formal parameter is here.
|
||||
augment void f();
|
||||
// ^
|
||||
// [diag.augmentationNamedFormalParameterMissing][context 1] The augmentation is missing the named formal parameter 'n1' from the declaration.
|
||||
augment void f({int? n1}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rn1__rn1_rn2() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({int? n1});
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f({int? n1, int? n2}) {}
|
||||
// ^^
|
||||
// [diag.augmentationNamedFormalParameterExtra][context 1] The augmentation has a named formal parameter 'n2', but the declaration doesn't.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rn1__rn1_rn2__rn1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({int? n1});
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f({int? n1, int? n2});
|
||||
// ^^
|
||||
// [diag.augmentationNamedFormalParameterExtra][context 1] The augmentation has a named formal parameter 'n2', but the declaration doesn't.
|
||||
augment void f({int? n1}) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rn1_rn2__rn1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({int? n1, int? n2});
|
||||
// ^^
|
||||
// [context 1] The formal parameter is here.
|
||||
augment void f({int? n1}) {}
|
||||
// ^
|
||||
// [diag.augmentationNamedFormalParameterMissing][context 1] The augmentation is missing the named formal parameter 'n2' from the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rn1_rn2__rn2() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({int? n1, int? n2});
|
||||
// ^^
|
||||
// [context 1] The formal parameter is here.
|
||||
augment void f({int? n2}) {}
|
||||
// ^
|
||||
// [diag.augmentationNamedFormalParameterMissing][context 1] The augmentation is missing the named formal parameter 'n1' from the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rn1_rn2_rn3__rn1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({int? n1, int? n2, int? n3});
|
||||
// ^^
|
||||
// [context 1] The formal parameter is here.
|
||||
// ^^
|
||||
// [context 2] The formal parameter is here.
|
||||
augment void f({int? n1}) {}
|
||||
// ^
|
||||
// [diag.augmentationNamedFormalParameterMissing][context 1] The augmentation is missing the named formal parameter 'n2' from the declaration.
|
||||
// [diag.augmentationNamedFormalParameterMissing][context 2] The augmentation is missing the named formal parameter 'n3' from the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rn1_rn2_rn3__rn1_rn3() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f({int? n1, int? n2, int? n3});
|
||||
// ^^
|
||||
// [context 1] The formal parameter is here.
|
||||
augment void f({int? n1, int? n3}) {}
|
||||
// ^
|
||||
// [diag.augmentationNamedFormalParameterMissing][context 1] The augmentation is missing the named formal parameter 'n2' from the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rP1__rp1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int? p1);
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f([int? p1]) {}
|
||||
// ^
|
||||
// [diag.augmentationRequiredPositionalFormalParameterCount][context 1] The augmentation has 0 required positional formal parameters, but the declaration has 1.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rp1__rP1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f([int? p1]);
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f(int? p1) {}
|
||||
// ^^
|
||||
// [diag.augmentationRequiredPositionalFormalParameterCount][context 1] The augmentation has 1 required positional formal parameters, but the declaration has 0.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rP1__rP1_rP2_rP3() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int? p1);
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f(int? p1, int? p2, int? p3) {}
|
||||
// ^^
|
||||
// [diag.augmentationRequiredPositionalFormalParameterCount][context 1] The augmentation has 3 required positional formal parameters, but the declaration has 1.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rP1__rP1_rp2_rp3() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int? p1);
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f(int? p1, [int? p2, int? p3]) {}
|
||||
// ^
|
||||
// [diag.augmentationOptionalPositionalFormalParameterCount][context 1] The augmentation has 2 optional positional formal parameters, but the declaration has 0.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rP1_rn1__rP1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int? p1, {int? n1});
|
||||
// ^^
|
||||
// [context 1] The formal parameter is here.
|
||||
augment void f(int? p1) {}
|
||||
// ^
|
||||
// [diag.augmentationNamedFormalParameterMissing][context 1] The augmentation is missing the named formal parameter 'n1' from the declaration.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rP1_rP2__rP1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int? p1, int? p2);
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f(int? p1) {}
|
||||
// ^
|
||||
// [diag.augmentationRequiredPositionalFormalParameterCount][context 1] The augmentation has 1 required positional formal parameters, but the declaration has 2.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rP1_rp2__rP1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int? p1, [int? p2]);
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f(int? p1) {}
|
||||
// ^
|
||||
// [diag.augmentationOptionalPositionalFormalParameterCount][context 1] The augmentation has 0 optional positional formal parameters, but the declaration has 1.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rP1_rP2__rP1_rp2() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int? p1, int? p2);
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f(int? p1, [int? p2]) {}
|
||||
// ^
|
||||
// [diag.augmentationRequiredPositionalFormalParameterCount][context 1] The augmentation has 1 required positional formal parameters, but the declaration has 2.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_rP1_rp2__rP1_rP2() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
void f(int? p1, [int? p2]);
|
||||
// ^
|
||||
// [context 1] The declaration being augmented.
|
||||
augment void f(int? p1, int? p2) {}
|
||||
// ^^
|
||||
// [diag.augmentationRequiredPositionalFormalParameterCount][context 1] The augmentation has 2 required positional formal parameters, but the declaration has 1.
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelSetter_rP1__rP1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
set foo(int? p1);
|
||||
augment set foo(int? p1) {}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelVariable_inducedSetter_rP1__rP1() async {
|
||||
await resolveTestCodeWithDiagnostics(r'''
|
||||
int foo = 0;
|
||||
augment void set foo(int p1);
|
||||
''');
|
||||
}
|
||||
}
|
||||
@@ -592,7 +592,7 @@ class A {
|
||||
A(this.x);
|
||||
//^
|
||||
// [context 1] The complete declaration is here.
|
||||
augment A() {}
|
||||
augment A(int x) {}
|
||||
//^^^^^^^
|
||||
// [diag.constructorAlreadyComplete][context 1] The augmentation can't provide a body, initializers, or initializing formal or super formal parameters because the constructor is already complete.
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ import 'async_keyword_used_as_identifier_test.dart'
|
||||
as async_keyword_used_as_identifier;
|
||||
import 'augmentation_extends_clause_already_present_test.dart'
|
||||
as augmentation_extends_clause_already_present;
|
||||
import 'augmentation_formal_parameter_shape_test.dart'
|
||||
as augmentation_formal_parameter_shape;
|
||||
import 'augmentation_modifier_extra_test.dart' as augmentation_modifier_extra;
|
||||
import 'augmentation_modifier_missing_test.dart'
|
||||
as augmentation_modifier_missing;
|
||||
@@ -991,6 +993,7 @@ main() {
|
||||
async_for_in_wrong_context.main();
|
||||
async_keyword_used_as_identifier.main();
|
||||
augmentation_extends_clause_already_present.main();
|
||||
augmentation_formal_parameter_shape.main();
|
||||
augmentation_modifier_extra.main();
|
||||
augmentation_modifier_missing.main();
|
||||
augmentation_of_different_declaration_kind.main();
|
||||
|
||||
Reference in New Issue
Block a user