File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1762,6 +1762,15 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
17621762 * being called is one of the object methods.
17631763 */
17641764 bool _inferMethodInvocationObject (MethodInvocation node) {
1765+ // If we have a call like `toString()` don't infer it.
1766+ //
1767+ // Either: it's really `this.toString()` and we shouldn't need inference,
1768+ // or it's a call to a function that happens to be called `toString()` and
1769+ // we shouldn't infer.
1770+ if (node.target == null ) {
1771+ return false ;
1772+ }
1773+
17651774 // Object methods called on dynamic targets can have their types improved.
17661775 String name = node.methodName.name;
17671776 MethodElement inferredElement =
Original file line number Diff line number Diff line change @@ -12172,6 +12172,20 @@ main() {
1217212172 code, typeProvider.dynamicType, typeProvider.intType);
1217312173 }
1217412174
12175+ void test_localVariableInference_declaredType_disabled_for_toString () {
12176+ String name = 'toString' ;
12177+ String code = '''
12178+ main() {
12179+ dynamic $name = () => null;
12180+ $name (); // marker
12181+ }''' ;
12182+ SimpleIdentifier identifier = _findMarkedIdentifier (code, "$name = " );
12183+ expect (identifier.staticType, typeProvider.dynamicType);
12184+ SimpleIdentifier call = _findMarkedIdentifier (code, "(); // marker" );
12185+ expect (call.staticType, typeProvider.dynamicType);
12186+ expect ((call.parent as Expression ).staticType, typeProvider.dynamicType);
12187+ }
12188+
1217512189 void test_localVariableInference_noInitializer_disabled () {
1217612190 String code = r'''
1217712191main() {
You can’t perform that action at this time.
0 commit comments