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
2 changes: 1 addition & 1 deletion src/fsharp/infos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ type MethInfo =
let formalRetTy = ImportReturnTypeFromMetadata amap m ilminfo.RawMetadata.Return.Type ilminfo.RawMetadata.Return.CustomAttrs ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys
let formalParams =
[ [ for p in ilminfo.RawMetadata.Parameters do
let paramType = ImportILTypeFromMetadata amap m ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys p.Type
let paramType = ImportILTypeFromMetadataWithAttributes amap m ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys p.Type p.CustomAttrs
yield TSlotParam(p.Name, paramType, p.IsIn, p.IsOut, p.IsOptional, []) ] ]
formalRetTy, formalParams
#if !NO_EXTENSIONTYPING
Expand Down
21 changes: 19 additions & 2 deletions tests/fsharp/Compiler/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open System.Diagnostics
open System.IO
open System.Text
open System.Diagnostics
open System.Collections.Generic
open System.Reflection
open FSharp.Compiler.Text
open FSharp.Compiler.SourceCodeServices
Expand All @@ -17,6 +18,9 @@ open System.Runtime.Loader
#endif
open NUnit.Framework
open System.Reflection.Emit
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.CSharp
open FSharp.Compiler.UnitTests.Utilities

[<Sealed>]
type ILVerifier (dllFilePath: string) =
Expand Down Expand Up @@ -52,12 +56,18 @@ type CompileOutput =
| Library
| Exe

type CompilationReference = private CompilationReference of Compilation * staticLink: bool with
type CompilationReference =
private
Comment on lines +59 to +60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: type private is more idiomatic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type private makes the whole type private which is not what I want. I only want to make the union cases private to the module.

| CompilationReference of Compilation * staticLink: bool
| TestCompilationReference of TestCompilation

static member CreateFSharp(cmpl: Compilation, ?staticLink) =
let staticLink = defaultArg staticLink false
CompilationReference(cmpl, staticLink)

static member Create(cmpl: TestCompilation) =
TestCompilationReference cmpl

and Compilation = private Compilation of string * SourceKind * CompileOutput * options: string[] * CompilationReference list with

static member Create(source, sourceKind, output, ?options, ?cmplRefs) =
Expand Down Expand Up @@ -257,7 +267,14 @@ let main argv = 0"""
|> List.map (fun cmpl ->
match cmpl with
| CompilationReference (cmpl, staticLink) ->
compileCompilationAux disposals ignoreWarnings cmpl, staticLink)
compileCompilationAux disposals ignoreWarnings cmpl, staticLink
| TestCompilationReference (cmpl) ->
let tmp = Path.GetTempFileName()
disposals.Add({ new IDisposable with
member _.Dispose() =
try File.Delete tmp with | _ -> () })
cmpl.EmitAsFile tmp
(([||], tmp), []), false)
Comment on lines +271 to +277
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it this was just leaving stuff around?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all new, so nothing was being left around before. But yes, once I create a tmp file, I need to make sure we always try to delete it on dispose.


let compilationRefs =
compiledRefs
Expand Down
41 changes: 41 additions & 0 deletions tests/fsharp/Compiler/Language/ByrefTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace FSharp.Compiler.UnitTests

open NUnit.Framework
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.UnitTests.Utilities

[<TestFixture>]
module ByrefTests =
Expand Down Expand Up @@ -195,4 +196,44 @@ let test1 () =
"The value has been copied to ensure the original is not mutated by this operation or because the copy is implicit when returning a struct from a member and another member is then accessed"
)
|]
#endif

#if NETCOREAPP
[<Test>]
let ``Consume CSharp interface with a method that has a readonly byref`` () =
let cs =
"""
using System;
using System.Buffers;

namespace Example
{
public interface IMessageReader
{
bool TryParseMessage(in byte input);
}
}
"""
let fs =
"""
module Module1

open Example

type MyClass() =

interface IMessageReader with
member this.TryParseMessage(input: inref<byte>): bool =
failwith "Not Implemented"
"""

let csCmpl =
CompilationUtil.CreateCSharpCompilation(cs, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30)
|> CompilationReference.Create

let fsCmpl =
Compilation.Create(fs, Fsx, Library, cmplRefs = [csCmpl])

CompilerAssert.Compile fsCmpl

#endif
4 changes: 2 additions & 2 deletions tests/fsharp/Compiler/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type CompilationUtil private () =
[ CSharpSyntaxTree.ParseText (source, CSharpParseOptions lv) ],
references.As<MetadataReference>().AddRange additionalReferences,
CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary))
Some (TestCompilation.CSharp (c, flags))
TestCompilation.CSharp (c, flags)

static member CreateILCompilation (source: string) =
let compute =
Expand All @@ -139,4 +139,4 @@ type CompilationUtil private () =
try File.Delete ilFilePath with | _ -> ()
try File.Delete tmp with | _ -> ()
try File.Delete dllFilePath with | _ -> ()
Some (TestCompilation.IL (source, compute))
TestCompilation.IL (source, compute)