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

Diagnose statement in namespace #2764

Closed
HerrCai0907 opened this issue Oct 11, 2023 · 3 comments · Fixed by #2765
Closed

Diagnose statement in namespace #2764

HerrCai0907 opened this issue Oct 11, 2023 · 3 comments · Fixed by #2765
Labels

Comments

@HerrCai0907
Copy link
Member

HerrCai0907 commented Oct 11, 2023

Bug description

statement in namespace does not have any effect. It should be diagnosed.

Steps to reproduce

let a = 0;

namespace NS {
  a = 100; // here should be diagnosed
  export function foo(): void {
    trace("a", 1, a);
  }
}

export function _start(): void {
  trace("a", 1, a);
  NS.foo();
}

compile and run this code will get

a 0
a 0

AssemblyScript version

0.27.x

@HerrCai0907
Copy link
Member Author

from #2763

@HerrCai0907
Copy link
Member Author

HerrCai0907 commented Oct 11, 2023

in typescript, a should be 100 in both position

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._start = void 0;
var a = 0;
var NS;
(function (NS) {
    a = 100;
    function foo() {
        console.log("a", 1, a);
    }
    NS.foo = foo;
})(NS || (NS = {}));
function _start() {
    console.log("a", 1, a);
    NS.foo();
}
exports._start = _start;
_start();

@JesseCodeBones
Copy link
Contributor

according to typescript grammar, namespace can have top level statement.

namespaceDeclaration
    : Namespace namespaceName '{' statementList? '}'
    ;
statementList
    : statement+
    ;

so parse and compile top level statement should be reasonable in namespace

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

Successfully merging a pull request may close this issue.

2 participants