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
13 changes: 0 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,3 @@ nCrunchTemp_*

tests/FSharp.Compiler.Service.Tests/FSharp.CompilerService.SurfaceArea.netstandard.actual
*.vsp
/Z.fs
/Y.fs
/X.fs
/Library.fs
/Ghost.fs
/D.fsi
/D.fs
/C.fsi
/C.fs
/B.fsi
/B.fs
/A.fsi
/A.fs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests
namespace FSharp.Compiler.ComponentTests.EmittedIL

open NUnit.Framework
open Xunit
open FSharp.Compiler.Diagnostics
open FSharp.Test
open FSharp.Test.Utilities
open FSharp.Test.Compiler

[<TestFixture>]
module ByrefTests =
module byrefTests =

[<Test>]
[<Fact>]
let ``No defensive copy on .NET struct`` () =
CompilerAssert.Pass
"""
Expand Down Expand Up @@ -51,7 +50,7 @@ let test6 () =
DateTime.Now.Test().Test().Test()
"""

[<Test>]
[<Fact>]
let ``Extension method scope errors`` () =
CompilerAssert.TypeCheckWithErrors
"""
Expand Down Expand Up @@ -119,7 +118,7 @@ let f5 () =
// TODO: A better way to test the ones below are to use a custom struct in C# code that contains explicit use of their "readonly" keyword.
#if NETCOREAPP
// NETCORE makes DateTime a readonly struct; therefore, it should not error.
[<Test>]
[<Fact>]
let ``No defensive copy on .NET struct - netcore`` () =
CompilerAssert.Pass
"""
Expand Down Expand Up @@ -148,7 +147,7 @@ let test2 () =
"""
#else
// Note: Currently this is assuming NET472. That may change which might break these tests. Consider using custom C# code.
[<Test>]
[<Fact>]
let ``Defensive copy on .NET struct for inref`` () =
CompilerAssert.TypeCheckWithErrors
"""
Expand Down Expand Up @@ -201,7 +200,7 @@ let test1 () =
#endif

#if NETCOREAPP
[<Test>]
[<Fact>]
let ``Consume CSharp interface with a method that has a readonly byref`` () =
let cs =
"""
Expand Down Expand Up @@ -240,7 +239,7 @@ type MyClass() =

#endif

[<Test>]
[<Fact>]
let ``Can take native address to get a nativeptr of a mutable value`` () =
CompilerAssert.Pass
"""
Expand All @@ -252,7 +251,7 @@ let test () =
()
"""

[<Test>]
[<Fact>]
let ``Cannot take native address to get a nativeptr of an immmutable value`` () =
CompilerAssert.TypeCheckWithErrors
"""
Expand All @@ -266,8 +265,7 @@ let test () =
(FSharpDiagnosticSeverity.Error, 256, (6, 13, 6, 16), "A value must be mutable in order to mutate the contents or take the address of a value type, e.g. 'let mutable x = ...'")
|]

[<Test()>]
[<Ignore("Waiting for test to be aligned", Until = "2023-04-01 12:00:00Z")>]
[<Fact>]
let ``Returning an 'inref<_>' from a property should emit System.Runtime.CompilerServices.IsReadOnlyAttribute on the return type of the signature`` () =
let src =
"""
Expand Down Expand Up @@ -297,8 +295,56 @@ type C() =
|> verifyIL [verifyProperty;verifyMethod]
|> ignore

[<Test>]
[<Ignore("Waiting for test to be aligned", Until = "2023-04-01 12:00:00Z")>]
[<Fact>]
let ``Returning an 'inref<_>' from a property should emit System.Runtime.CompilerServices.IsReadOnlyAttribute on the return type of the signature and generate the `` () =
let src =
"""
module Test

type C() =
let x = 59
member _.X: inref<_> = &x
"""

let verifyProperty = """.property instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute)
X()
{
.custom instance void System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )
.get instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute) Test/C::get_X()
}"""

let verifyMethod = """.method public hidebysig specialname
instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute)
get_X() cil managed
{
.param [0]
.custom instance void System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )"""

let verifyIsReadOnlyAttribute = """
.class private auto ansi beforefieldinit System.Runtime.CompilerServices.IsReadOnlyAttribute
extends [System.Runtime]System.Attribute
{
.method public specialname rtspecialname
instance void .ctor() cil managed
{
.custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [netstandard]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
IL_0006: ret
} // end of method IsReadOnlyAttribute::.ctor

} // end of class System.Runtime.CompilerServices.IsReadOnlyAttribute"""

FSharp src
|> asNetStandard20
|> compile
|> verifyIL [verifyProperty;verifyMethod;verifyIsReadOnlyAttribute]
|> ignore

[<Fact>]
let ``Returning an 'inref<_>' from a generic method should emit System.Runtime.CompilerServices.IsReadOnlyAttribute on the return type of the signature`` () =
let src =
"""
Expand All @@ -320,8 +366,7 @@ type C<'T>() =
|> verifyIL [verifyMethod]
|> ignore

[<Test>]
[<Ignore("Waiting for test to be aligned", Until = "2023-04-01 12:00:00Z")>]
[<Fact>]
let ``Returning an 'inref<_>' from an abstract generic method should emit System.Runtime.CompilerServices.IsReadOnlyAttribute on the return type of the signature`` () =
let src =
"""
Expand All @@ -344,8 +389,7 @@ type C<'T>() =
|> verifyIL [verifyMethod]
|> ignore

[<Test>]
[<Ignore("Waiting for test to be aligned", Until = "2023-04-01 12:00:00Z")>]
[<Fact>]
let ``Returning an 'inref<_>' from an abstract property should emit System.Runtime.CompilerServices.IsReadOnlyAttribute on the return type of the signature`` () =
let src =
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Compile Include="EmittedIL\Inlining\Inlining.fs" />
<Compile Include="EmittedIL\ListExpressionStepping\ListExpressionStepping.fs" />
<Compile Include="EmittedIL\MethodImplAttribute\MethodImplAttribute.fs" />
<Compile Include="EmittedIL\Misc\byrefTests.fs" />
<Compile Include="EmittedIL\Misc\Misc.fs" />
<Compile Include="EmittedIL\operators\Operators.fs" />
<Compile Include="EmittedIL\Platform\Platform.fs" />
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.Test.Utilities/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ module rec Compiler =
let asNetStandard20 (cUnit: CompilationUnit) : CompilationUnit =
match cUnit with
| FS fs -> FS { fs with TargetFramework = TargetFramework.NetStandard20 }
| CS cs -> CS { cs with TargetFramework = TargetFramework.NetStandard20 }
| CS _ -> failwith "References are not supported in CS"
| IL _ -> failwith "References are not supported in IL"

let asExe (cUnit: CompilationUnit) : CompilationUnit =
Expand Down
1 change: 0 additions & 1 deletion tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<Compile Include="Compiler\Language\CustomCollectionTests.fs" />
<Compile Include="Compiler\Language\HatDesugaringTests.fs" />
<Compile Include="Compiler\Language\TypeAttributeTests.fs" />
<Compile Include="Compiler\Language\ByrefTests.fs" />
<Compile Include="Compiler\Language\StringInterpolation.fs" />
<Compile Include="Compiler\Language\InterfaceTests.fs" />
<Compile Include="Compiler\Language\AnonRecordTests.fs" />
Expand Down