-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ad-hoc fix for
ref readonly
parameters (#16232)
* Test should fail * Threat ref readonly as inref * Fixed condition in test
- Loading branch information
1 parent
c2031c2
commit 24ef671
Showing
4 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/FSharp.Compiler.ComponentTests/Interop/ByrefTests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace Interop | ||
|
||
open FSharp.Test | ||
open FSharp.Test.Compiler | ||
|
||
module ``Byref interop verification tests`` = | ||
|
||
[<FactForNETCOREAPP>] | ||
let ``Test that ref readonly is treated as inref`` () = | ||
|
||
FSharp """ | ||
module ByrefTest | ||
open System.Runtime.CompilerServices | ||
type MyRecord = { Value : int } with | ||
member this.SetValue(v: int) = (Unsafe.AsRef<int> &this.Value) <- v | ||
let check mr = | ||
if mr.Value <> 1 then | ||
failwith "Value should be 1" | ||
mr.SetValue(42) | ||
if mr.Value <> 42 then | ||
failwith $"Value should be 42, but is {mr.Value}" | ||
0 | ||
[<EntryPoint>] | ||
let main _ = | ||
let mr = { Value = 1 } | ||
check mr | ||
""" | ||
|> asExe | ||
|> compileAndRun | ||
|> shouldSucceed | ||
|
||
[<FactForNETCOREAPP>] | ||
let ``Test that ref readonly is treated as inref for ROS .ctor`` () = | ||
FSharp """ | ||
module Foo | ||
open System | ||
[<EntryPoint>] | ||
let main _ = | ||
let mutable bt: int = 42 | ||
let ros = ReadOnlySpan<int>(&bt) | ||
if ros.Length <> 1 || ros[0] <> 42 then | ||
failwith "Unexpected result" | ||
0 | ||
""" | ||
|> asExe | ||
|> compileAndRun | ||
|> shouldSucceed |