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

task model: Classes with call methods don't type check #356

Closed
vsmenon opened this issue Sep 29, 2015 · 4 comments
Closed

task model: Classes with call methods don't type check #356

vsmenon opened this issue Sep 29, 2015 · 4 comments

Comments

@vsmenon
Copy link
Contributor

vsmenon commented Sep 29, 2015

In the task model branch, I'm getting an error on the assignment in main below:

class A {
  int call(String str) => 499;
}

typedef int F(String str);

void main() {
  F f = new A();
}

Error is:

severe: [AnalyzerMessage] A value of type 'A' cannot be assigned to a variable of type 'F'

No errors or warnings in bleeding_edge.

@jmesserly
Copy link
Contributor

I can take a look

@jmesserly
Copy link
Contributor

Looks like we used to handle this in rules.dart, getCallMethodType, which is used in various places for type checking

@jmesserly
Copy link
Contributor

Strangely, that logic looks to have been ported to resolver.dart, StrongTypeSystemImpl. In fact almost this exact test case exists:

  void test_isSubtypeOf_call_method() {
    ClassElementImpl classBottom = ElementFactory.classElement2("Bottom");
    MethodElement methodBottom =
        ElementFactory.methodElement("call", objectType, <DartType>[intType]);
    classBottom.methods = <MethodElement>[methodBottom];

    DartType top = TypeBuilder.functionType(<DartType>[intType], objectType);
    InterfaceType bottom = classBottom.type;

    _checkIsStrictSubtypeOf(bottom, top);
  }

  void test_isAssignableTo_call_method() {
    ClassElementImpl classBottom = ElementFactory.classElement2("B");
    MethodElement methodBottom =
        ElementFactory.methodElement("call", objectType, <DartType>[intType]);
    classBottom.methods = <MethodElement>[methodBottom];

    DartType top = TypeBuilder.functionType(<DartType>[intType], objectType);
    InterfaceType bottom = classBottom.type;

    _checkIsAssignableTo(top, bottom);
  }

@jmesserly
Copy link
Contributor

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

No branches or pull requests

2 participants