Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deducing type error when the method having generic parameter #551

Closed
LiaoPeng opened this issue Mar 19, 2019 · 2 comments
Closed

Deducing type error when the method having generic parameter #551

LiaoPeng opened this issue Mar 19, 2019 · 2 comments

Comments

@LiaoPeng
Copy link
Contributor

The source code.

import "allocator/arena";
import { Action , getMethod, Method, Action1, getMethod1 } from "./name";

declare function sayHello(): void;

sayHello();

export function add(x: i32, y: i32): i32 {
  return x + y;
}

var mth: Method = getMethod("name");
Action.attach(mth, "");


var mth1 = getMethod1("name");
Action1.attachWithoutData(mth1);
Action1.attach(mth1, "");

The compiled result:

ERROR TS2304: Cannot find name 'Method1'.

   static attach<T>(mth: Method1, data: T):void  {
                         ~~~~~~~
 in name.ts(29,24)


ERROR: Compile error
    at exports.main (https://assemblyscript.github.io/assemblyscript/dist/asc.js:1:457291)
    at Object.eval [as main] (eval at d (https://webassembly.studio/dist/main.bundle.js:1:32473), <anonymous>:20:12)
    at r.eval [as promiseMaker] (eval at gulp (https://webassembly.studio/dist/main.bundle.js:1:34093), <anonymous>:7:7)
    at o.makePromise (https://webassembly.studio/dist/main.bundle.js:1:31658)
    at s.runInstance (https://webassembly.studio/dist/main.bundle.js:1:31954)

[info]: Task build is completed
Saving Project ...
Saved Project OK

The below code compiled successful.

var mth: Method = getMethod("name");
Action.attach(mth, "");

I expected the below code also compiled successful.

var mth1 = getMethod1("name");
Action1.attach(mth1, "");

@dcodeIO
Copy link
Member

dcodeIO commented Mar 19, 2019

This actually looks like a resolver error.

// name.ts

export class Method1 {
}

export function getMethod1(name: string): Method1 {
  return changetype<Method1>(0);
}

export class Action1 {
  static attach<T>(mth: Method1, data: T): void  {
  }
}

This doesn't work:

import { Action1, getMethod1 } from "./name";

var mth1 = getMethod1("name");
Action1.attach(mth1, "");

but this does:

import { Action1, Method1, getMethod1 } from "./name";
//                   ^ !
var mth1 = getMethod1("name");
Action1.attach(mth1, "");

@dcodeIO
Copy link
Member

dcodeIO commented May 27, 2020

Closing this issue as part of 2020 vacuum because it appears to have been solved meanwhile. The latest failing example did work in a quick test. If there are any remaining issues, feel free to open a new issue or re-open this one.

@dcodeIO dcodeIO closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants