File tree 2 files changed +23
-0
lines changed
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> {
1762
1762
* being called is one of the object methods.
1763
1763
*/
1764
1764
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
+
1765
1774
// Object methods called on dynamic targets can have their types improved.
1766
1775
String name = node.methodName.name;
1767
1776
MethodElement inferredElement =
Original file line number Diff line number Diff line change @@ -12172,6 +12172,20 @@ main() {
12172
12172
code, typeProvider.dynamicType, typeProvider.intType);
12173
12173
}
12174
12174
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
+
12175
12189
void test_localVariableInference_noInitializer_disabled () {
12176
12190
String code = r'''
12177
12191
main() {
You can’t perform that action at this time.
0 commit comments