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

asc crash when use same name in class and namespace #2793

Open
HerrCai0907 opened this issue Nov 14, 2023 · 1 comment · May be fixed by #2805
Open

asc crash when use same name in class and namespace #2793

HerrCai0907 opened this issue Nov 14, 2023 · 1 comment · May be fixed by #2805
Assignees
Labels

Comments

@HerrCai0907
Copy link
Member

Bug description

class NS {
  static v: i32 = 2;
}

namespace NS {
  let v: i32 = 1;
}
Fatal: Module::addGlobal: assembly/index/NS.v already exists

▌ Whoops, the AssemblyScript compiler has crashed during compile :-(
▌ 
▌ There is no stack trace. Perhaps a Binaryen exception above / in console?
▌ 
▌ > undefined
▌ 
▌ If you see where the error is, feel free to send us a pull request. If not,
▌ please let us know: https://github.com/AssemblyScript/assemblyscript/issues
▌ 
▌ Thank you!

Steps to reproduce

npm run asbuild

AssemblyScript version

latest

@CountBleck
Copy link
Member

CountBleck commented Nov 14, 2023

That looks like a bug from how internal names are generated.

@CountBleck CountBleck self-assigned this Nov 14, 2023
CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Nov 20, 2023
This commit changes the delimiter between namespaces and their members
from "." to "::" in internal names. The new delimiter certainly feels
very un-JavaScript-y, but the meaning is still recognizable, and these
names aren't exposed to users in most cases anyway. Still, this is a
breaking change, as it affects the import names for `declare namespace`
members (as seen in tests/compiler/declare.js), and transform authors
will also need to update their code accordingly.

Fixes AssemblyScript#2793.
CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Nov 21, 2023
This isn't fully TS compatible, but refactors targeting internal names,
scoping, merging, etc. are needed to become more compatible. For
instance, if namespace members had unique separators in internal names,
then a non-exported namespace member would override a static class
member, assuming the names are the same.

Note that this change doesn't prevent the compiler from attempting to
compile the duplicate global, and hence the previous commit is needed
for this to work fully.

Barely fixes AssemblyScript#2793.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants