kevingadd/JSIL — Issue #57: Previously untranslatable gotos still produce bad JS
Author: kevingadd
Created: 2012-01-04 09:39:04+00:00
State: open
Labels: Bug, Missing Feature

Whoops. The problem from issue #34 still exists, in a different form. It turns out this special usage of gotos (not possible in C#; only the C# compiler can generate this IL) produces control flow that is basically impossible to emulate in JS. Right now, the generated JS looks like this:

```javascript

$.prototype.IEnumerator_MoveNext = function () {
var $label0 = "$entry0";
$labelgroup0:
while (true) {
switch ($label0) {
case "$entry0":
switch (this.$state) {
case 0:
this.$state = -1;
this.i = 0;
break;
case 1:
this.$state = -1;
++this.i;
break;
default:
$label0 = "IL_74";
continue $labelgroup0;
;
}
if (this.i >= this.count) {
$label0 = "IL_74";
continue $labelgroup0;
;
} else {
this.$current = (this.start + this.i);
this.$state = 1;
var result = true;
}
return result;
$label0 = "IL_74";
continue $labelgroup0;
case "IL_74":
result = false;
break $labelgroup0;
}
}
};

```

While the reference to the original label is preserved in the correct location, there's no way to return control flow after executing the label.

I can't really come up with a good solution for this. I think control flow like this may require removing all non-goto control flow structures (branches, loops, switch statements) from a function in order to reproduce the original logic. Yuck.