Skip to content
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

Compiler crash on exception handler construct #1091

Closed
FilippoPolo opened this issue Feb 27, 2020 · 1 comment
Closed

Compiler crash on exception handler construct #1091

FilippoPolo opened this issue Feb 27, 2020 · 1 comment
Assignees
Projects

Comments

@FilippoPolo
Copy link

The following F# code:

type test =
    {
        test_field: string[] option
    }
let foo =
    let bar = try (0).ToString() with e -> e.ToString()
    let bar = [|bar|]
    { test_field = Some bar }

When passed through W# 4.6.0.361, results in:

WebSharper error FS9001 : Global error : System.Exception: Undefined variable during writing JavaScript: $3�   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1637.Invoke(String message) in E:\A\_work\130\s\src\fsharp\FSharp.Core\printf.fs:line 1637�   at WebSharper.Compiler.JavaScriptWriter.transformId(Environment env, Id id)�   at WebSharper.Compiler.JavaScriptWriter.transformExpr(Environment env, Expression expr)�   at WebSharper.Compiler.JavaScriptWriter.transformStatement(Environment env, Statement statement)�   at WebSharper.Compiler.JavaScriptWriter.add@286-6.Invoke(Statement a)�   at Microsoft.FSharp.Primitives.Basics.List.iter[T](FSharpFunc`2 f, FSharpList`1 x) in E:\A\_work\130\s\src\fsharp\FSharp.Core\local.fs:line 91�   at WebSharper.Compiler.JavaScriptWriter.flatten@283(Environment env, FSharpList`1 s)�   at WebSharper.Compiler.JavaScriptWriter.transformStatement(Environment env, Statement statement)�   at WebSharper.Compiler.JavaScriptWriter.transformStatement@409-15.Invoke(Unit unitVar0)�   at WebSharper.Compiler.JavaScriptWriter.withFuncDecls@323(Environment env, FSharpFunc`2 f)�   at WebSharper.Compiler.JavaScriptWriter.add@286-6.Invoke(Statement a)�   at WebSharper.Compiler.JavaScriptWriter.add@286-6.Invoke(Statement a)�   at Microsoft.FSharp.Primitives.Basics.List.iter[T](FSharpFunc`2 f, FSharpList`1 x) in E:\A\_work\130\s\src\fsharp\FSharp.Core\local.fs:line 91�   at WebSharper.Compiler.JavaScriptWriter.flatten@283(Environment env, FSharpList`1 s)�   at WebSharper.Compiler.JavaScriptWriter.transformStatement(Environment env, Statement statement)�   at WebSharper.Compiler.JavaScriptWriter.transformExpr(Environment env, Expression expr)�   at WebSharper.Compiler.JavaScriptWriter.transformExpr(Environment env, Expression expr)�   at WebSharper.Compiler.JavaScriptWriter.transformStatement(Environment env, Statement statement)�   at WebSharper.Compiler.JavaScriptWriter.add@286-6.Invoke(Statement a)�   at Microsoft.FSharp.Primitives.Basics.List.iter[T](FSharpFunc`2 f, FSharpList`1 x) in E:\A\_work\130\s\src\fsharp\FSharp.Core\local.fs:line 91�   at WebSharper.Compiler.JavaScriptWriter.flatten@283(Environment env, FSharpList`1 s)�   at WebSharper.Compiler.JavaScriptWriter.transformStatement(Environment env, Statement statement)�   at WebSharper.Compiler.JavaScriptWriter.transformExpr(Environment env, Expression expr)�   at WebSharper.Compiler.JavaScriptWriter.transformExpr(Environment env, Expression expr)�   at WebSharper.Compiler.Packager.exprToString(Preferences pref, FSharpFunc`2 getWriter, Expression statement)�   at WebSharper.Compiler.FrontEnd.CreateResources(FSharpOption`1 comp, Info refMeta, Info current, Boolean sourceMap, FSharpOption`1 closures, AssemblyDefinition a)�   at WebSharper.Compiler.FrontEnd.ModifyCecilAssembly(FSharpOption`1 comp, Info refMeta, Info current, Boolean sourceMap, FSharpOption`1 closures, AssemblyDefinition a)�   at WebSharper.FSharp.Program.Compile$cont@219-3(WsConfig config, Loader loader, FSharpList`1 refs, Task`1 wsRefsMeta, Compilation comp, Info currentMeta, Unit unitVar)�   at WebSharper.FSharp.Program.Compile$cont@202-2(WsConfig config, Boolean isBundleOnly, Loader loader, FSharpList`1 refs, Task`1 wsRefsMeta, Compilation comp, Unit unitVar)�   at WebSharper.FSharp.Program.Compile$cont@64(WsConfig config, WarnSettings warnSettings, String thisName, Unit unitVar)�   at WebSharper.FSharp.Program.compileMain$cont@310(String[] argv, Unit unitVar)�   at WebSharper.FSharp.Program.main(String[] argv)

From testing, this seems to only happen with an option of array, and only if the value comes from a try/with construct.

@Jand42
Copy link
Member

Jand42 commented Mar 2, 2020

@FilippoPolo Thanks for the report and the small example!

Indeed, it is some optimizer bug, I managed to shrink the example a more, just a try expression within an array is enough:

let foo = [| (try (0).ToString() with e -> e.ToString()) |]

Looking into it using ASTTests.fsx that can print intermediate expressions as processed by WebSharper compiler.

@Jand42 Jand42 added the bug label Mar 2, 2020
@Jand42 Jand42 self-assigned this Mar 2, 2020
@Jand42 Jand42 added this to High priority for current version in Releases Mar 2, 2020
@Jand42 Jand42 closed this as completed in ccef5ad Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Releases
High priority for current version
Development

No branches or pull requests

2 participants