Skip to content

Assigning value to the mutable variable causes an exception #146

@kirillgarbar

Description

@kirillgarbar

Describe the bug
Assigning value to the mutable variable using quotation injected method causes an exception in some cases. Looks like exception occures only then there are match statement in the method. Also, if variable is not mutable it works fine

To Reproduce

let op1 =
    <@ fun (x: bool option) ->
        let mutable res = None
        match x with
        | Some _ -> res <- Some true
        | None -> ()
        res
         @>

let op2 =
    <@ fun (x: bool option) ->
        x
         @>

let kernelEx =
    <@ fun (ndRange: Range1D) ->
        let mutable sum: bool option = None
        sum <- (%op1) (Some true) @>

let kernelOK1 =
    <@ fun (ndRange: Range1D) ->
        let mutable sum: bool option = None
        sum <- (%op2) (Some true) @>

let kernelOK2 =
    <@ fun (ndRange: Range1D) ->
        let mutable sum: bool option = None
        let newSum = (%op1) (Some true)
        sum <- newSum @>

context.Compile kernelOK1
context.Compile kernelOK2
context.Compile kernelEx

Expected behavior
All kernels should compile

Actual behavior
Only last 2 kernels compile. First kernel causes System.InvalidCastException: Unable to cast object of type 'Brahma.FSharp.OpenCL.AST.StatementBlock1[Brahma.FSharp.OpenCL.AST.Lang]' to type 'Brahma.FSharp.OpenCL.AST.Expression1[Brahma.FSharp.OpenCL.AST.Lang]'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions