Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6932,18 +6932,17 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, optOrigExpr, flds, mWholeExpr
let requiresCtor = (GetCtorShapeCounter env = 1) // Get special expression forms for constructors
let haveCtor = Option.isSome inherits

let optOrigExprInfo, tpenv =
let optOrigExpr, tpenv =
match optOrigExpr with
| None -> None, tpenv
| Some (origExpr, _) ->
match inherits with
| Some (_, _, mInherits, _, _) -> error(Error(FSComp.SR.tcInvalidRecordConstruction(), mInherits))
| None ->
let olde, tpenv = TcExpr cenv overallTy env tpenv origExpr
let oldvaddr, oldvaddre = mkCompGenLocal mWholeExpr "inputRecord" (if isStructTy cenv.g overallTy then mkByrefTy cenv.g overallTy else overallTy)
Some (olde, oldvaddr, oldvaddre), tpenv
Some (olde), tpenv

let hasOrigExpr = optOrigExprInfo.IsSome
let hasOrigExpr = optOrigExpr.IsSome

let fldsList =
let flds =
Expand All @@ -6970,6 +6969,13 @@ and TcRecdExpr cenv overallTy env tpenv (inherits, optOrigExpr, flds, mWholeExpr
| Some v -> yield n, v
| None -> () ]

let optOrigExprInfo =
match optOrigExpr with
| None -> None
| Some(olde) ->
let oldvaddr, oldvaddre = mkCompGenLocal mWholeExpr "inputRecord" (if isStructTy cenv.g overallTy then mkByrefTy cenv.g overallTy else overallTy)
Some(olde, oldvaddr, oldvaddre)

if hasOrigExpr && not (isRecdTy cenv.g overallTy) then
errorR(Error(FSComp.SR.tcExpressionFormRequiresRecordTypes(), mWholeExpr))

Expand Down
10 changes: 9 additions & 1 deletion tests/fsharp/core/byrefs/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,15 @@ module ByrefReturnMemberTests =
module OutRefToInRefClassMethod2 =
type C() =
static member f1 (x: inref<'T>) = 1
let f2 (x: outref<'T>) = C.f1(&x)
let f2 (x: outref<'T>) = C.f1(&x)

module TestStructRecord =
[<Struct>]
type AnItem =
{ Link: string }

let link item =
{ item with Link = "" }

let aa =
if !failures then (stdout.WriteLine "Test Failed"; exit 1)
Expand Down