Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

task model: inferring type of variable that is explicit dynamic #349

Closed
jmesserly opened this issue Sep 25, 2015 · 12 comments
Closed

task model: inferring type of variable that is explicit dynamic #349

jmesserly opened this issue Sep 25, 2015 · 12 comments
Assignees

Comments

@jmesserly
Copy link
Contributor

This is from 'conversion and dynamic invoke' checker_test.dart:

        dynamic toString = () => null;
        (/*info:DynamicInvoke*/toString());
@jmesserly
Copy link
Contributor Author

I'm able to reproduce this in Analyzer with a unit test (added to same file/class as test_localVariableInference_declaredType_disabled):

  void test_localVariableInference_declaredType_disabled_for_functions() {
    String code = r'''
main() {
  dynamic v = () => null;
  v; // marker
}''';
    SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = ");
    expect(identifier.staticType, typeProvider.dynamicType);
    identifier = _findMarkedIdentifier(code, "; // marker");
    expect(identifier.staticType, typeProvider.dynamicType);
  }

edit: hmm, maybe not... investigating further ... above test is passing. The "failure" was caused by a test typo on my part

@jmesserly
Copy link
Contributor Author

Here's a test that reproduces:

  void test_localVariableInference_declaredType_disabled_for_toString() {
    String name = 'toString';
    String code = '''
main() {
  dynamic $name = () => null;
  $name(); // marker
}''';
    SimpleIdentifier identifier = _findMarkedIdentifier(code, "$name = ");
    expect(identifier.staticType, typeProvider.dynamicType);
    SimpleIdentifier call = _findMarkedIdentifier(code, "(); // marker");
    expect(call.staticType, typeProvider.dynamicType);
    expect((call.parent as Expression).staticType, typeProvider.dynamicType);
    // edit: removed FunctionExpressionInvocation assert
  }

what is super crazy: if you change the name from toString to something like toStrin it behaves differently. The AST structure has a MethodInvocation node, and the type is correctly dynamic. Whereas with toString the failure is:

FAIL: StrongModeTypePropagationTest | test_localVariableInference_declaredType_disabled_for_toString
  Expected: DynamicTypeImpl:<dynamic>
    Actual: FunctionTypeImpl:<() → String>

@leafpetersen
Copy link
Contributor

That may either be an analyzer bug, or a bug in the code that I added to handle object methods. I suspect the former because I don't think that should be a method invocation node - it should be a FunctionExpressionInvocation node, shouldn't it?

@jmesserly
Copy link
Contributor Author

yes ... I'm trying to figure out why it parses different ... that's just spooky.
It is a MethodInvocation node with a null target, so I think it's the same semantically, but still...

@leafpetersen
Copy link
Contributor

My take would be that it should not be a MethodInvocation node, since it's not a method invocation. If it is valid to have a method invocation node, then the special case code for object methods in static_type_analyzer.dart (_inferObjectAccess and _inferMethodInvocationObject) needs to be fixed to handle this (as should probably the type propagation code in the analyzer proper in that file, which I believe makes the same assumptions). Possibly the _isObjectProperty and _isObjectMethod code in ddc's checker.dart should be fixed as well. @bwilkerson , is that a correct parse or is this a bug?

@jmesserly
Copy link
Contributor Author

oh ... it's always a MethodInvocation ... one mystery solved at least. I was confused because it wasn't getting to my FunctionExpressionInvocation assert in the test. Whew!

@jmesserly
Copy link
Contributor Author

(that is: MethodInvocation with a null target)

@jmesserly
Copy link
Contributor Author

https://codereview.chromium.org/1368793004/ has the fix. Thanks Leaf!

jmesserly pushed a commit to dart-lang/sdk that referenced this issue Sep 26, 2015
we incorrectly thought `toString()` was a call to `Object.toString()`

See dart-archive/dev_compiler#349 for more context

[email protected]

Review URL: https://codereview.chromium.org//1368793004 .
@jmesserly
Copy link
Contributor Author

landed. Thanks Brian for the review!

@jmesserly jmesserly reopened this Sep 28, 2015
@jmesserly
Copy link
Contributor Author

reopening ... the original issue is fixed, but a library prefix like helper.toString() still fails. Doh!

@jmesserly
Copy link
Contributor Author

jmesserly pushed a commit to dart-lang/sdk that referenced this issue Sep 28, 2015
See dart-archive/dev_compiler#349 for context.

The prefix fix handled `toString()` but not `library_prefix.toString()`

[email protected], [email protected]

Review URL: https://codereview.chromium.org//1374773003 .
@jmesserly
Copy link
Contributor Author

landed that one. here's the final fix for checker_test https://codereview.chromium.org/1374813002/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants