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

copyOfStruct error when setting a property returned from a function #8899

Open
mrakgr opened this issue Apr 7, 2020 · 3 comments
Open

copyOfStruct error when setting a property returned from a function #8899

mrakgr opened this issue Apr 7, 2020 · 3 comments
Assignees
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone

Comments

@mrakgr
Copy link

mrakgr commented Apr 7, 2020

See also #8069 which is being treated as a duplicate of this

module Bug

type Q() =
    member val t = 0 with get, set

let f c x = c () <- x

let q = Q()
f (fun _ -> q.t) 2
1>C:\Users\Marko\Source\Repos\Lithe\Lithe\bug.fs(6,13): error FS0971: Undefined value 'copyOfStruct : 'a ref'

This only gives me an error at build time, not in VS.

@mrakgr mrakgr changed the title Returning a property from a function does not result in an Intellisense error Setting a property returned from a function does not result in an Intellisense error Apr 7, 2020
@cartermp cartermp added this to the Backlog milestone Apr 14, 2020
@dsyme dsyme changed the title Setting a property returned from a function does not result in an Intellisense error copyOfStruct error when setting a property returned from a function Sep 1, 2020
@dsyme dsyme added the Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. label Sep 1, 2020
@abelbraaksma
Copy link
Contributor

abelbraaksma commented Sep 1, 2020

From #8069 there comes this similar repro, which should find its way to tests once this gets picked up:

[<EntryPoint>]
let main argv = 

    let mutable way1 = [|0|]
    let mutable way2 = [|0|]
    (way1,way2) <- ([|1|],[|2|])   // FS0971 copyOfStruct error after compiling
    printfn "%A" argv
    0 

@ForNeVeR
Copy link
Contributor

ForNeVeR commented Feb 7, 2021

Less arcane way of reproducing the issue:

open System
type C() =
    member _.M() =
       let mutable a, b = 3, 4
       (a, b) <- 4, 5 // error FS0971: Undefined value 'copyOfStruct : (int * int) ref'
       a, b

sharplab

@abelbraaksma
Copy link
Contributor

@ForNeVeR, interesting. Previously, assignment to a tuple led to a different error iirc. After all, a tuple is immutable (regardless of the declaration, which is short for two distinct declarations of variables), so an error makes sense, but not that one.

@dsyme dsyme self-assigned this Apr 4, 2022
@dsyme dsyme added Area-Compiler-Checking Type checking, attributes and all aspects of logic checking and removed Area-Compiler labels Apr 4, 2022
@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
Status: New
Development

No branches or pull requests

5 participants