Skip to content

Commit 358d088

Browse files
T-GroCopilot
andauthored
Add regression test for #3532: FSharpEntity.IsByRef is false for byref`1 (#19485)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent df38aef commit 358d088

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

tests/FSharp.Compiler.Service.Tests/Symbols.fs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,59 @@ let test = System.DateTimeKind.Utc
13711371
failwith "Expected metadata text, got None"
13721372
| _ -> failwith "Expected FSharpEntity symbol"
13731373

1374+
module IsByRef =
1375+
// https://github.com/dotnet/fsharp/issues/3532
1376+
[<Fact>]
1377+
let ``FSharpEntity.IsByRef is true for byref return type of address-of operator`` () =
1378+
let _, checkResults =
1379+
getParseAndCheckResults
1380+
"""
1381+
let mutable x = 1
1382+
let y = &x
1383+
"""
1384+
1385+
let symbolUse = findSymbolUseByName "op_AddressOf" checkResults
1386+
1387+
match symbolUse.Symbol with
1388+
| :? FSharpMemberOrFunctionOrValue as mfv ->
1389+
let retTy = mfv.ReturnParameter.Type
1390+
1391+
Assert.True(
1392+
retTy.HasTypeDefinition,
1393+
$"Expected return type of op_AddressOf to have a TypeDefinition, got: %A{retTy}"
1394+
)
1395+
1396+
Assert.True(
1397+
retTy.TypeDefinition.IsByRef,
1398+
$"Expected return type TypeDefinition.IsByRef = true for op_AddressOf, got entity: %s{retTy.TypeDefinition.DisplayName}"
1399+
)
1400+
| symbol -> failwith $"Expected FSharpMemberOrFunctionOrValue but got %A{symbol}"
1401+
1402+
[<Fact>]
1403+
let ``FSharpEntity.IsByRef is true for byref type used explicitly`` () =
1404+
let _, checkResults =
1405+
getParseAndCheckResults
1406+
"""
1407+
let f (x: byref<int>) = x <- 42
1408+
"""
1409+
1410+
let symbolUse = findSymbolUseByName "f" checkResults
1411+
1412+
match symbolUse.Symbol with
1413+
| :? FSharpMemberOrFunctionOrValue as mfv ->
1414+
let paramTy = mfv.CurriedParameterGroups.[0].[0].Type
1415+
1416+
Assert.True(
1417+
paramTy.HasTypeDefinition,
1418+
$"Expected byref parameter type to have a TypeDefinition, got: %A{paramTy}"
1419+
)
1420+
1421+
Assert.True(
1422+
paramTy.TypeDefinition.IsByRef,
1423+
$"Expected parameter TypeDefinition.IsByRef = true for byref<int>, got entity: %s{paramTy.TypeDefinition.DisplayName}"
1424+
)
1425+
| symbol -> failwith $"Expected FSharpMemberOrFunctionOrValue but got %A{symbol}"
1426+
13741427
module OperatorsWithDots =
13751428
// https://github.com/dotnet/fsharp/issues/14057
13761429
[<Fact>]
@@ -1417,4 +1470,4 @@ let result = 1 -.- 2
14171470
let range = usageSymbols.[0].Range
14181471
let rangeLength = range.EndColumn - range.StartColumn
14191472

1420-
Assert.Equal(3, rangeLength)
1473+
Assert.Equal(3, rangeLength)

0 commit comments

Comments
 (0)