You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Basically not possible in AS for nowfunctionambiguousReturn(){return{}}// could be:// return;// or// return {};
More valid example:
letambiguousAssignment=newArray<Array<i32>>()leta=ambiguousAssignment[1].sort()// could be:// let a = ambiguousAssignment;// [1].sort()// or// let a = ambiguousAssignment[1].sort();
I propose to identify such ambiguities and give a syntax error suggesting to insert semicolon ";" or remove the line break separating the keyword and "{" or "[" tokens.
is always equivalent to return; which is different than the other example. Anything after a return statement without a semi colon never interacts with the return statement. But in the example
leta=ambiguousAssignment[1].sort()
the item on the next line does interact with the previous line.
In my mind, there's no ambiguity with the return statement.
I believe we should not error on these, but we should match JS syntax. People should learn the syntax.
A warning might be ok, as long as it allows compilation of the program (with valid syntax) to complete.
I believe that any ambiguity that might create undefined behaviour or very different behaviour should produce an error. JS design especially as far as errors is concerned should be avoided altogether. JS is designed to execute in as many cases as possible and only throw a syntax error in the most extreme cases.
Activity
trusktr commentedon Nov 17, 2021
Just to clarify,
is always equivalent to
return;which is different than the other example. Anything after areturnstatement without a semi colon never interacts with thereturnstatement. But in the examplethe item on the next line does interact with the previous line.
In my mind, there's no ambiguity with the return statement.
I believe we should not error on these, but we should match JS syntax. People should learn the syntax.
A warning might be ok, as long as it allows compilation of the program (with valid syntax) to complete.
I write all my code without semi colons.
MaxGraey commentedon Nov 17, 2021
I believe that any ambiguity that might create undefined behaviour or very different behaviour should produce an error. JS design especially as far as errors is concerned should be avoided altogether. JS is designed to execute in as many cases as possible and only throw a syntax error in the most extreme cases.
MaxGraey commentedon Sep 1, 2022
More example:
afederl commentedon Oct 15, 2026
Here is another example of unexpected behavior that may even be considered a bug:
Unlike JavaScript and TypeScript, AssemblyScript produces the following output:
In JavaScript and TypeScript, both versions produce the same output: