Skip to content

[Dev16] The address of the variable '{name}' cannot be used at this point. #5983

@TIHan

Description

@TIHan

This is only reproducible in Dev16. Dev15.9 does not experience this issue.

So, this code:

open System

[<Struct>]
type Movement =
    {
        Yaw: float32
        Pitch: float32
        IsMovingForward: bool
        IsMovingLeft: bool
        IsMovingBackward: bool
        IsMovingRight: bool
    }

    static member Default =
        {
            Yaw = 0.f
            Pitch = 0.f
            IsMovingForward = false
            IsMovingLeft = false
            IsMovingBackward = false
            IsMovingRight = false
        }

type MouseButtonType =
    | Left = 1
    | Middle = 2
    | Right = 3
    | X1 = 4
    | X2 = 5

type InputEvent =
    | KeyPressed of char
    | KeyReleased of char
    | MouseButtonPressed of MouseButtonType
    | MouseButtonReleased of MouseButtonType
    | MouseWheelScrolled of 
        x: int * y: int
    | MouseMoved of
        x: int * y: int * xrel: int * yrel: int

[<RequireQualifiedAccess>]
type InputState = { Events: InputEvent list }

let getMovement (input: InputState) mov =
    (mov, input.Events)
    ||> List.fold (fun mov evt ->
        match evt with
        | MouseMoved (x, y, xrel, yrel) ->
            { mov with
                Yaw = mov.Yaw + (single xrel * -0.25f) * (float32 Math.PI / 180.f)
                Pitch = mov.Pitch + (single yrel * -0.25f) * (float32 Math.PI / 180.f)
            }

        | KeyPressed x when x = 'w' -> { mov with IsMovingForward = true }
        | KeyReleased x when x = 'w' -> { mov with IsMovingForward = false }

        | KeyPressed x when x = 'a' -> { mov with IsMovingLeft = true }
        | KeyReleased x when x = 'a' -> { mov with IsMovingLeft = false }

        | KeyPressed x when x = 's' -> { mov with IsMovingBackward = true }
        | KeyReleased x when x = 's' -> { mov with IsMovingBackward = false }

        | KeyPressed x when x = 'd' -> { mov with IsMovingRight = true }
        | KeyReleased x when x = 'd' -> { mov with IsMovingRight = false }
        | _ -> mov
    )

[<EntryPoint>]
let main argv =
    0

Gives an error:
Error FS0421 The address of the variable 'mov' cannot be used at this point
At this location:

            { mov with // <----- The ERROR
                Yaw = mov.Yaw + (single xrel * -0.25f) * (float32 Math.PI / 180.f)
                Pitch = mov.Pitch + (single yrel * -0.25f) * (float32 Math.PI / 180.f)
            }

The error happens when at the end of an expression we are not allowed to return the address of a variable. The TAST produced does this for some reason.

I'm not for certain, but I think it caused by this PR: #5148 given how this change affected constructs exactly like this and how it's only in Dev16.

// cc @dsyme

Edit:

Adding a line above where the error occured when we use mov compiles fine:

            let _itWorksNow = mov.Yaw
            { mov with
                Yaw = mov.Yaw + (single xrel * -0.25f) * (float32 Math.PI / 180.f)
                Pitch = mov.Pitch + (single yrel * -0.25f) * (float32 Math.PI / 180.f)
            }

Metadata

Metadata

Assignees

Labels

Impact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.Regression

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions