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

Generic calls don't work with async #538

Closed
harryterkelsen opened this issue Apr 29, 2016 · 5 comments
Closed

Generic calls don't work with async #538

harryterkelsen opened this issue Apr 29, 2016 · 5 comments

Comments

@harryterkelsen
Copy link
Contributor

import 'dart:async';

class A {
  Future<int> bar() async {
    var result = await foo/*<int>*/(1);
    return result + 1;
  }

  Future/*<T>*/ foo/*<T>*/(/*=T*/ x) async {
    var result = await new Future/*<T>*/.value(x);
    return result;
  }
}

Future<Null> main() async {
  var a = new A();
  var x = await a.bar();
  print(x);
}

generates this:

  hello.A = class A extends core.Object {
    bar() {
      return dart.async((function*() {
        let result = (yield this.foo(core.int)(1));
        return dart.notNull(result) + 1;
      }).bind(this), core.int);
    }
    foo(x) {
      return dart.async(function*(x) {
        let result = (yield async.Future$(T).value(x));
        return result;
      }, T, x);
    }
  };
  dart.setSignature(hello.A, {
    methods: () => ({
      bar: [async.Future$(core.int), []],
      foo: [T => [async.Future$(T), [T]]]
    })
  });
  hello.main = function() {
    return dart.async(function*() {
      let a = new hello.A();
      let x = (yield a.bar());
      core.print(x);
    }, core.Null);
  };

The foo method isn't taking the T type parameter.

@harryterkelsen harryterkelsen changed the title Generic calls don't work inside async Generic calls don't work with async Apr 29, 2016
@harryterkelsen
Copy link
Contributor Author

harryterkelsen commented Apr 29, 2016

That example is too big, here's a smaller one with the same problem:

import 'dart:async';

Future/*<T>*/ foo/*<T>*/(/*=T*/ x) async => x;

main() async {
  print(await foo/*<int>*/(1));
}

@jmesserly
Copy link
Contributor

thanks, I can take a look. we have a lot of paths for generating function bodies so it's not terribly surprising. I'll also add to the tracking bug #435

@jmesserly jmesserly self-assigned this Apr 29, 2016
@jmesserly jmesserly mentioned this issue Apr 29, 2016
12 tasks
@jmesserly
Copy link
Contributor

jmesserly commented Apr 29, 2016

likely async*/sync* have the same issue.

@harryterkelsen
Copy link
Contributor Author

I think I found a 1-line fix, will send for review

@jmesserly
Copy link
Contributor

🎉

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