Skip to content

Commit 6865041

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 27098. Check that argument is assignable to parameter in call().
[email protected] Bug: #27098 Change-Id: I0d5ac65202b632646bd7b26170c55ab985d2523c Reviewed-on: https://dart-review.googlesource.com/52263 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent be47fa6 commit 6865041

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
9595
/**
9696
* The version of data format, should be incremented on every format change.
9797
*/
98-
static const int DATA_VERSION = 56;
98+
static const int DATA_VERSION = 57;
9999

100100
/**
101101
* The number of exception contexts allowed to write. Once this field is

pkg/analyzer/lib/src/generated/element_resolver.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,21 @@ class ElementResolver extends SimpleAstVisitor<Object> {
658658
DartType staticType = _resolver.strongMode
659659
? _getStaticTypeOrFunctionType(target)
660660
: _getStaticType(target);
661+
662+
if (_resolver.strongMode &&
663+
staticType is FunctionType &&
664+
methodName.name == FunctionElement.CALL_METHOD_NAME) {
665+
if (target is SimpleIdentifier) {
666+
methodName.staticElement = target.staticElement;
667+
}
668+
methodName.staticType = target.staticType;
669+
node.staticType = staticType;
670+
node.staticInvokeType = staticType;
671+
node.argumentList.correspondingStaticParameters =
672+
_computeCorrespondingParameters(node.argumentList, staticType);
673+
return null;
674+
}
675+
661676
DartType propagatedType = _getPropagatedType(target);
662677
staticElement = _resolveInvokedElementWithTarget(
663678
target, staticType, methodName, isConditional);

pkg/analyzer/test/generated/static_warning_code_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,20 @@ f(A a) {
368368
verify([source]);
369369
}
370370

371+
test_argumentTypeNotAssignable_call() async {
372+
resetWith(options: new AnalysisOptionsImpl()..strongMode = true);
373+
Source source = addSource(r'''
374+
typedef bool Predicate<T>(T object);
375+
376+
Predicate<String> f() => null;
377+
378+
void main() {
379+
f().call(3);
380+
}''');
381+
await computeAnalysisResult(source);
382+
assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
383+
}
384+
371385
test_argumentTypeNotAssignable_cascadeSecond() async {
372386
Source source = addSource(r'''
373387
// filler filler filler filler filler filler filler filler filler filler

0 commit comments

Comments
 (0)