Skip to content

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Mar 26, 2020

This should fix #1186 by emitting a Cannot find name 'x'. diagnostic instead of aborting.

@MaxGraey
Copy link
Member

MaxGraey commented Mar 26, 2020

btw with shadowing it also should emit compile error in TS and runtime ref error in JS (ReferenceError: Cannot access 'd' before initialization)

let d = 1;
export function testLet2(): i32 {
  let d = (d = 2, 3);
  return d;
}

But currently compile without any issues: https://webassembly.studio/?f=ym35gg4wwm

TS:

let d = 1;
export function testLet2(): number {
  d = 2;
  // let d = 3;  // uncomment this will cause compiler error in TS
  return d;
}

@dcodeIO
Copy link
Member Author

dcodeIO commented Mar 27, 2020

Hmm, yeah, that complicates things, so might need a proper mechanism.

@dcodeIO
Copy link
Member Author

dcodeIO commented Mar 28, 2020

A proper fix for some of this will require some sort of pre-pass binding variables to scopes before compiling a scope's statements. While not exactly JS currently, this seems rather low priority and I'm fine with

function foo(): void {
  a = 1;
  var a: i32;
}

erroring because it's bad code anyway. Referencing a global from the outer scope there is unfortunate, though.

@MaxGraey
Copy link
Member

I agree. Also this quite antistatic case. So just printing proper error for all cases will be fine

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 this pull request may close these issues.

Assertion failed when modifying a variable from within init
2 participants