WebSharper

With Zafir.4.0.159.36-beta6 and a recursive function to unit non-terminating JavaScript is generated:

1
2
3
4
5
6
7
8
9
10
11
let rec inferTypes = function
    | (first::rest) ->
        if first = 7 then failwith "Seven is not OK"
        inferTypes rest
    | _ -> ()

[<SPAEntryPoint>]
let Main () =

    let x = inferTypes [1;3;4]
    Console.Log x

it looks like the optimisation is confused somehow:

1
2
3
4
5
6
7
8
9
 Client.inferTypes=function(a)
 {
  while(true)
   if(a.$==1)
    {
     a.$0===7?Operators.FailWith("Seven is not OK"):void 0;
     a=a.$1;
    }
 };

while it's not my preferred approach it definitely shouldn't generate non-terminating code! It seems as if the optimization is relying on early returns to break the while(true) which don't exist in this circumstance.

We occasionally use patterns like this to scan complex types for faults then throw rather than returning some kind of error type through the call hierarchy.

It works with WebSharper 3.6.14.237