mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
Report inference failure on return types of typedefs and generic function types
Change-Id: I9da541785f75c0da5121bb7058d3ad726ff00e12 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117522 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
40cc975932
commit
3637e78014
|
@ -343,6 +343,12 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
super.visitFunctionExpression(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitFunctionTypeAlias(FunctionTypeAlias node) {
|
||||
_checkStrictInferenceReturnType(node.returnType, node, node.name.name);
|
||||
super.visitFunctionTypeAlias(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
|
||||
_checkStrictInferenceReturnType(
|
||||
|
@ -351,6 +357,25 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
super.visitFunctionTypedFormalParameter(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitGenericFunctionType(GenericFunctionType node) {
|
||||
// GenericTypeAlias is handled in [visitGenericTypeAlias], where a proper
|
||||
// name can be reported in any message.
|
||||
if (node.parent is! GenericTypeAlias) {
|
||||
_checkStrictInferenceReturnType(node.returnType, node, node.toString());
|
||||
}
|
||||
super.visitGenericFunctionType(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitGenericTypeAlias(GenericTypeAlias node) {
|
||||
if (node.functionType != null) {
|
||||
_checkStrictInferenceReturnType(
|
||||
node.functionType.returnType, node, node.name.name);
|
||||
}
|
||||
super.visitGenericTypeAlias(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitImportDirective(ImportDirective node) {
|
||||
_checkForDeprecatedMemberUse(node.uriElement, node);
|
||||
|
|
|
@ -156,6 +156,22 @@ void f(int callback()) {
|
|||
''');
|
||||
}
|
||||
|
||||
test_genericFunctionType() async {
|
||||
await assertErrorsInCode(r'''
|
||||
Function(int) f = (int n) {
|
||||
print(n);
|
||||
};
|
||||
''', [error(HintCode.INFERENCE_FAILURE_ON_FUNCTION_RETURN_TYPE, 0, 13)]);
|
||||
}
|
||||
|
||||
test_genericFunctionType_withReturnType() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void Function(int) f = (int n) {
|
||||
print(n);
|
||||
};
|
||||
''');
|
||||
}
|
||||
|
||||
test_localFunction() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
class C {
|
||||
|
@ -199,6 +215,30 @@ f() {
|
|||
test_topLevelFunction_withReturnType() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
dynamic f() => 7;
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_classic() async {
|
||||
await assertErrorsInCode(r'''
|
||||
typedef Callback(int i);
|
||||
''', [error(HintCode.INFERENCE_FAILURE_ON_FUNCTION_RETURN_TYPE, 0, 24)]);
|
||||
}
|
||||
|
||||
test_typedef_classic_withReturnType() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
typedef void Callback(int i);
|
||||
''');
|
||||
}
|
||||
|
||||
test_typedef_modern() async {
|
||||
await assertErrorsInCode(r'''
|
||||
typedef Callback = Function(int i);
|
||||
''', [error(HintCode.INFERENCE_FAILURE_ON_FUNCTION_RETURN_TYPE, 0, 35)]);
|
||||
}
|
||||
|
||||
test_typedef_modern_withReturnType() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
typedef Callback = void Function(int i);
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue