-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
fix: add diagnose for non-declarative statements in namespace #2765
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AS and TS has difference behavior for this case.
TS will throw diagnose Block-scoped variable 'a' used before its declaration
but AS will not.
But I think it is different topic with this PR. It is a generic issue both in namespace and function.
Should we introduce variable scope analysis to handle these cases.
@dcodeIO @CountBleck WDYT.
let a: number = 0;
namespace NS {
a = 100;
export function foo(): void {
trace("a", 1, a);
}
let a = 200;
}
export function _start(): void {
trace("aaaaa", 1, a);
NS.foo();
}
This issue could happened in any scope: top level, function body, namespace and etc.
invalid case:
invalid case:
let a:i32 = 1;
function foo():void{
a = 42;
let a: i32 = 0;
}
foo(); (module
(type $none_=>_none (func))
(global $namespace/a (mut i32) (i32.const 1))
(global $~lib/memory/__data_end i32 (i32.const 8))
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 32776))
(global $~lib/memory/__heap_base i32 (i32.const 32776))
(memory $0 0)
(table $0 1 1 funcref)
(elem $0 (i32.const 1))
(export "memory" (memory $0))
(start $~start)
(func $namespace/foo
(local $a i32)
i32.const 42
global.set $namespace/a
i32.const 0
local.set $a
)
(func $start:namespace
call $namespace/foo
)
(func $~start
call $start:namespace
)
)
|
Okay, this one thing is unacceptable. There should be a temporal deadzone above that |
Sure, but this PR shouldn't be merged (yet) if it allows weird stuff as shown above. |
I think we can diagnose "not implement" as temporary solution. Totally ignoring statement in namespace is also weird stuff. |
Yeah, that |
In typescript, it has |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since AS cannot fully support namesapce as TS, maybe diagnose "not implement" as temporary solution.
6d6969d
to
e352a59
Compare
Hi Congcong, |
Fixes #2764.