diff --git a/src/fsharp/infos.fs b/src/fsharp/infos.fs index 1db4e36b356..63db80bae85 100755 --- a/src/fsharp/infos.fs +++ b/src/fsharp/infos.fs @@ -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 diff --git a/tests/fsharp/Compiler/CompilerAssert.fs b/tests/fsharp/Compiler/CompilerAssert.fs index 9f0bc09553b..ef0e591a0c1 100644 --- a/tests/fsharp/Compiler/CompilerAssert.fs +++ b/tests/fsharp/Compiler/CompilerAssert.fs @@ -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 @@ -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 [] type ILVerifier (dllFilePath: string) = @@ -52,12 +56,18 @@ type CompileOutput = | Library | Exe -type CompilationReference = private CompilationReference of Compilation * staticLink: bool with +type CompilationReference = + private + | 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) = @@ -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) let compilationRefs = compiledRefs diff --git a/tests/fsharp/Compiler/Language/ByrefTests.fs b/tests/fsharp/Compiler/Language/ByrefTests.fs index 2797125d791..d09f9f4cf24 100644 --- a/tests/fsharp/Compiler/Language/ByrefTests.fs +++ b/tests/fsharp/Compiler/Language/ByrefTests.fs @@ -4,6 +4,7 @@ namespace FSharp.Compiler.UnitTests open NUnit.Framework open FSharp.Compiler.SourceCodeServices +open FSharp.Compiler.UnitTests.Utilities [] module ByrefTests = @@ -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 + [] + 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): 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 \ No newline at end of file diff --git a/tests/fsharp/Compiler/Utilities.fs b/tests/fsharp/Compiler/Utilities.fs index 29de21ad3e3..b55707fdb4e 100644 --- a/tests/fsharp/Compiler/Utilities.fs +++ b/tests/fsharp/Compiler/Utilities.fs @@ -120,7 +120,7 @@ type CompilationUtil private () = [ CSharpSyntaxTree.ParseText (source, CSharpParseOptions lv) ], references.As().AddRange additionalReferences, CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary)) - Some (TestCompilation.CSharp (c, flags)) + TestCompilation.CSharp (c, flags) static member CreateILCompilation (source: string) = let compute = @@ -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)) \ No newline at end of file + TestCompilation.IL (source, compute) \ No newline at end of file