-
Notifications
You must be signed in to change notification settings - Fork 854
Open
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingArea-Compiler-Checking-Byrefbyref, inref, outref, byref-like types, NativePtr, function pointers, struct semanticsbyref, inref, outref, byref-like types, NativePtr, function pointers, struct semanticsBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone
Description
The following code is not compiled:
[<Struct>]
type Person =
{ Name: string; Age: int }
member x.WithAge age =
{ x with Age = age }
with the error FS3232: Struct members cannot return the address of fields of the struct by reference, pointing to the x inside WithAge member.
The problem is that x has type inref, but nothing prevents from constructing another record instance from it.
The known workaround is to declare another variable from x:
[<Struct>]
type Person =
{ Name: string; Age: int }
member x.WithAge age =
let copy = x
{ copy with Age = age }
Environment:
- .NET Core 2.2
- VS 2019 16.2.5
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingArea-Compiler-Checking-Byrefbyref, inref, outref, byref-like types, NativePtr, function pointers, struct semanticsbyref, inref, outref, byref-like types, NativePtr, function pointers, struct semanticsBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Type
Projects
Status
New