Skip to content

Namespaces for types don't work #423

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

Closed
vgrichina opened this issue Jan 16, 2019 · 11 comments
Closed

Namespaces for types don't work #423

vgrichina opened this issue Jan 16, 2019 · 11 comments
Labels

Comments

@vgrichina
Copy link

See https://studio.nearprotocol.com/?f=XfZ2mUv for working example.

Basically if you have:

namespace Outer {
  export class Inner {

  }
}

it doesn't look that any references to Inner actually work.

E.g. none of these compile so far:

let cannotDeclareVariable: Outer.Inner = null;

function cannotReturn(): Outer.Inner {
}

function cannotTakeAargument(arg: Outer.Inner): void {
}

Do you have any suggestion on how to fix this?

@vgrichina
Copy link
Author

Note that if I have a type in separate module and try to do:

import * as Outer from "./outer";

I also get compilation problem when I try to use Outer.Inner.

@vgrichina
Copy link
Author

vgrichina commented Jan 17, 2019

@dcodeIO looks like first issue is gone, but issue remains with:

import * as Outer from "./outer";

@dcodeIO
Copy link
Member

dcodeIO commented Jan 17, 2019

What's the complete code there? Asking because the Outer namespace isn't exported in your example, and it should look somewhat like this to work:

// a.ts
export namespace Outer {
  export class Inner {
  }
}
// b.ts
import * as A from "./a";

A.Outer.Inner; // ?

@vgrichina
Copy link
Author

@dcodeIO sorry, here's working example:

https://studio.nearprotocol.com/?f=utg1efv31

@dcodeIO
Copy link
Member

dcodeIO commented Jan 17, 2019

Thanks, I see now. Doesn't seem that there's a super easy fix for this. The elements map only contains the filespace, but there are no (recursive) aliases of its children which could be looked up by a simple string search. What we'd need instead is a multi-level map to be able to resolve symbols at specific points in the tree without having to rely on a global map, hmm...

@vgrichina
Copy link
Author

@dcodeIO what does happen when I have, say:

import { Inner } from "./outer";

and then use Inner anywhere. How is Inner resolved?

@vgrichina
Copy link
Author

vgrichina commented Jan 17, 2019

@dcodeIO BTW, looks like this only fails for variable declaration, but works for usage in function types and params.

These seem to compile fine:

function cannotReturn(): Outer.Inner {
}

function cannotTakeAargument(arg: Outer.Inner): void {
}

but this fails:

let cannotDeclareVariable: Outer.Inner = null;

EDIT: Looks they actually also fail once you try calling functions.

@vgrichina
Copy link
Author

vgrichina commented Jan 17, 2019

Importing and renaming individual classes works apparently, see:
https://studio.nearprotocol.com/?f=sfi79r9in

So basically for now just gonna do stuff like:

import {Inner as Outer_Inner} from "./outer";

However I feel that it's better to just give compiler error on:

import * as whatever from "./module";

Then it'll be clearly marked as unsupported feature, cause right now it's not clear what's going on – it only works for some isolated cases.

vgrichina added a commit to nearprotocol/assemblyscript that referenced this issue Jan 17, 2019
Required some hackery cause cannot import module as a whole, see:
AssemblyScript#423
vgrichina added a commit to nearprotocol/assemblyscript that referenced this issue Jan 17, 2019
Required some hackery cause cannot import module as a whole, see:
AssemblyScript#423
@dcodeIO
Copy link
Member

dcodeIO commented Jan 24, 2019

Will keep this in mind while switching to symbol tables in #424. Going to implement proper tree-based lookups there.

@vgrichina
Copy link
Author

@dcodeIO this one actually also looks related:
#429

@dcodeIO
Copy link
Member

dcodeIO commented Feb 7, 2019

Closing in favor of #473, which is our tracking issue for similar related issues now.

@dcodeIO dcodeIO closed this as completed Feb 7, 2019
@dcodeIO dcodeIO mentioned this issue Feb 19, 2019
5 tasks
dcodeIO added a commit that referenced this issue Feb 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants