fabulous-dev / Fabulous

Declarative UI framework for cross-platform mobile & desktop apps, using MVU and F# functional programming
https://fabulous.dev
Apache License 2.0
1.13k stars 122 forks source link

Multiple for loops in builder causes crash #1044

Closed edgarfgp closed 1 year ago

edgarfgp commented 1 year ago

This is the same as https://github.com/edgarfgp/Fabulous.AST/issues/31

[<Test>]
    let ``Multiple for loops in builder causes crash`` () =
        let view model =
            Stack() {
                Label($"Foo") // It also crashes only with the multiple for loops 
                Label($"bar") // It also crashes only with the multiple for loops 
                for i = 0 to 10 do
                    Label($"T{i}")
                for i = 10 to 20 do
                    Label($"T{i}")
                for i = 20  to 30 do
                    Label($"T{i}")
            }

        let init () = true
        let update (_: unit) addColor = not addColor
        let program = StatefulWidget.mkSimpleView init update view

        let instance = Run.Instance program
        instance.Start() |> ignore

        ()
System.ArgumentException : Source array was not long enough. Check the source index, length, and the array's lower bounds. (Parameter 'sourceArray')
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
   at Fabulous.StackAllocatedCollections.MutStackArray1.combineMut[v](T`1& a, T`1 b) in /Users/edgardev/Projects/Fabulous/src/Fabulous/Array.fs:line 480
   at Fabulous.Tests.APISketchTests.Attributes.view@710-56TT.Invoke(a model) in /Users/edgardev/Projects/Fabulous/src/Fabulous.Tests/APISketchTests/APISketchTests.fs:line 718
   at Fabulous.Tests.APISketchTests.TestUI_Widgets.Run.Instance`4.Start(arg arg) in /Users/edgardev/Projects/Fabulous/src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs:line 241
   at Fabulous.Tests.APISketchTests.Attributes.Multiple for loops in builder causes crash() in /Users/edgardev/Projects/Fabulous/src/Fabulous.Tests/APISketchTests/APISketchTests.fs:line 728
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)