Skip to content

Commit d953562

Browse files
authored
Add tests for consuming statics in interfaces (#13097)
* Upgraded Roslyn and VS packages + added tests for consuming statics in interfaces * Skip abstract statics test on non-netcore * Fix path to csc * Reverted roslyn version to 4.2.*
1 parent 2eb7dc7 commit d953562

File tree

10 files changed

+96
-22
lines changed

10 files changed

+96
-22
lines changed

eng/Build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ try {
509509
Create-Directory $resultsRoot
510510
UpdatePath
511511
$env:HOSTED_COMPILER = 1
512-
$env:CSC_PIPE = "$nugetPackages\Microsoft.Net.Compilers\2.7.0\tools\csc.exe"
512+
$env:CSC_PIPE = "$nugetPackages\Microsoft.Net.Compilers\4.3.0-1.22220.8\tools\csc.exe"
513513
$env:FSCOREDLLPATH = "$ArtifactsDir\bin\fsc\$configuration\net472\FSharp.Core.dll"
514514
$env:LINK_EXE = "$RepoRoot\tests\fsharpqa\testenv\bin\link\link.exe"
515515
$env:OSARCH = $env:PROCESSOR_ARCHITECTURE

eng/Versions.props

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@
113113
<SystemRuntimeCompilerServicesUnsafeVersion>6.0.0</SystemRuntimeCompilerServicesUnsafeVersion>
114114
<SystemValueTupleVersion>4.5.0</SystemValueTupleVersion>
115115
<!-- VisualStudio package versions -->
116-
<VisualStudioImplementationPackagesVersion>17.0.391-preview-g5e248c9073</VisualStudioImplementationPackagesVersion>
117-
<VisualStudioContractPackagesVersion>17.0.0-previews-4-31709-430</VisualStudioContractPackagesVersion>
116+
<VisualStudioImplementationPackagesVersion>17.2.178-preview</VisualStudioImplementationPackagesVersion>
117+
<VisualStudioContractPackagesVersion>17.2.0-preview-1-32131-009</VisualStudioContractPackagesVersion>
118118
<VisualStudioProjectSystemPackagesVersion>17.0.77-pre-g62a6cb5699</VisualStudioProjectSystemPackagesVersion>
119119
<MicrosoftVisualStudioInteropVersion>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioInteropVersion>
120120
<MicrosoftInternalVisualStudioInteropVersion>$(VisualStudioContractPackagesVersion)</MicrosoftInternalVisualStudioInteropVersion>
@@ -135,7 +135,7 @@
135135
<EnvDTEVersion>$(VisualStudioContractPackagesVersion)</EnvDTEVersion>
136136
<EnvDTE80Version>$(VisualStudioContractPackagesVersion)</EnvDTE80Version>
137137
<!-- Roslyn packages -->
138-
<RoslynVersion>4.1.0-1.21511.14</RoslynVersion>
138+
<RoslynVersion>4.2.0-2.22103.11</RoslynVersion>
139139
<MicrosoftCodeAnalysisEditorFeaturesVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesVersion>
140140
<MicrosoftCodeAnalysisEditorFeaturesTextVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesTextVersion>
141141
<MicrosoftCodeAnalysisEditorFeaturesWpfVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesWpfVersion>
@@ -169,7 +169,7 @@
169169
<MicrosoftVisualStudioShellFrameworkVersion>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioShellFrameworkVersion>
170170
<MicrosoftVisualStudioPackageLanguageService150Version>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioPackageLanguageService150Version>
171171
<!-- Misc. Visual Studio packages -->
172-
<MicrosoftVisualStudioRpcContractsVersion>17.0.50-preview-0002-0025</MicrosoftVisualStudioRpcContractsVersion>
172+
<MicrosoftVisualStudioRpcContractsVersion>17.2.22-alpha</MicrosoftVisualStudioRpcContractsVersion>
173173
<MicrosoftVisualStudioComponentModelHostVersion>$(VisualStudioImplementationPackagesVersion)</MicrosoftVisualStudioComponentModelHostVersion>
174174
<MicrosoftVisualFSharpMicrosoftVisualStudioShellUIInternalVersion>17.0.0</MicrosoftVisualFSharpMicrosoftVisualStudioShellUIInternalVersion>
175175
<MicrosoftVisualStudioDesignerInterfacesVersion>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioDesignerInterfacesVersion>
@@ -185,9 +185,9 @@
185185
<MicrosoftVisualStudioShellImmutable150Version>15.0.25123-Dev15Preview</MicrosoftVisualStudioShellImmutable150Version>
186186
<MicrosoftVisualStudioShellInterop160DesignTimeVersion>16.0.1</MicrosoftVisualStudioShellInterop160DesignTimeVersion>
187187
<MicrosoftVisualStudioShellInterop16DesignTimeVersion>16.0.28924.11111</MicrosoftVisualStudioShellInterop16DesignTimeVersion>
188-
<MicrosoftVisualStudioThreadingVersion>17.0.46-alpha</MicrosoftVisualStudioThreadingVersion>
188+
<MicrosoftVisualStudioThreadingVersion>17.2.10-alpha</MicrosoftVisualStudioThreadingVersion>
189189
<MicrosoftVisualStudioUtilitiesVersion>$(VisualStudioContractPackagesVersion)</MicrosoftVisualStudioUtilitiesVersion>
190-
<MicrosoftVisualStudioValidationVersion>17.0.23-alpha</MicrosoftVisualStudioValidationVersion>
190+
<MicrosoftVisualStudioValidationVersion>17.0.46</MicrosoftVisualStudioValidationVersion>
191191
<MicrosoftVisualStudioWCFReferenceInteropVersion>9.0.30729</MicrosoftVisualStudioWCFReferenceInteropVersion>
192192
<VSSDKDebuggerVisualizersVersion>12.0.4</VSSDKDebuggerVisualizersVersion>
193193
<VSSDKVSLangProjVersion>7.0.4</VSSDKVSLangProjVersion>
@@ -203,7 +203,7 @@
203203
<FSharpDataTypeProvidersVersion>4.3.0.0</FSharpDataTypeProvidersVersion>
204204
<MicrosoftCompositionVersion>1.0.30</MicrosoftCompositionVersion>
205205
<MicrosoftMSXMLVersion>8.0.0</MicrosoftMSXMLVersion>
206-
<MicrosoftNetCompilersVersion>2.7.0</MicrosoftNetCompilersVersion>
206+
<MicrosoftNetCompilersVersion>4.3.0-1.22220.8</MicrosoftNetCompilersVersion>
207207
<MicrosoftNETCoreAppRefVersion>3.1.0</MicrosoftNETCoreAppRefVersion>
208208
<MicrosoftNETCoreILDAsmVersion>5.0.0-preview.7.20364.11</MicrosoftNETCoreILDAsmVersion>
209209
<MicrosoftNETCoreILAsmVersion>5.0.0-preview.7.20364.11</MicrosoftNETCoreILAsmVersion>
@@ -214,8 +214,8 @@
214214
<NUnit3TestAdapterVersion>4.1.0</NUnit3TestAdapterVersion>
215215
<NunitXmlTestLoggerVersion>2.1.80</NunitXmlTestLoggerVersion>
216216
<RoslynToolsSignToolVersion>1.0.0-beta2-dev3</RoslynToolsSignToolVersion>
217-
<StreamJsonRpcVersion>2.8.21</StreamJsonRpcVersion>
218-
<NerdbankStreamsVersion>2.7.74</NerdbankStreamsVersion>
217+
<StreamJsonRpcVersion>2.11.34</StreamJsonRpcVersion>
218+
<NerdbankStreamsVersion>2.8.57</NerdbankStreamsVersion>
219219
<XUnitVersion>2.4.1</XUnitVersion>
220220
<XUnitRunnerVersion>2.4.2</XUnitRunnerVersion>
221221
<FluentAssertionsVersion>5.10.3</FluentAssertionsVersion>

tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi;" Exclude="@(Compile)">
22-
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
23-
</None>
24-
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
25-
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
26-
</None>
21+
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi;" Exclude="@(Compile)">
22+
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
23+
</None>
24+
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
25+
<Link>%(RelativeDir)\TestSource\%(Filename)%(Extension)</Link>
26+
</None>
2727
<Compile Include="Conformance\BasicGrammarElements\OperatorNames\OperatorNames.fs" />
2828
<Compile Include="Conformance\BasicGrammarElements\PrecedenceAndOperators\PrecedenceAndOperators.fs" />
2929
<Compile Include="Conformance\BasicTypeAndModuleDefinitions\ExceptionDefinitions\ExceptionDefinitions.fs" />
@@ -161,7 +161,8 @@
161161
<Compile Include="Language\CastingTests.fs" />
162162
<Compile Include="ConstraintSolver\PrimitiveConstraints.fs" />
163163
<Compile Include="ConstraintSolver\MemberConstraints.fs" />
164-
<Compile Include="Interop\SimpleInteropTests.fs" />
164+
<Compile Include="Interop\SimpleInteropTests.fs" />
165+
<Compile Include="Interop\StaticsInInterfaces.fs" />
165166
<Compile Include="Interop\VisibilityTests.fs" />
166167
<Compile Include="Scripting\Interactive.fs" />
167168
<Compile Include="TypeChecks\CheckDeclarationsTests.fs" />
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
namespace FSharp.Compiler.ComponentTests.Interop
3+
4+
open Xunit
5+
open FSharp.Test.Compiler
6+
open FSharp.Test
7+
8+
module ``Static Methods In Interfaces`` =
9+
10+
let withCSharpLanguageVersion (ver: CSharpLanguageVersion) (cUnit: CompilationUnit) : CompilationUnit =
11+
match cUnit with
12+
| CS cs -> CS { cs with LangVersion = ver }
13+
| _ -> failwith "Only supported in C#"
14+
15+
let csharpBaseClass =
16+
CSharp """
17+
namespace StaticsInInterfaces
18+
{
19+
public interface IGetNext<T> where T : IGetNext<T>
20+
{
21+
static abstract T Next(T other);
22+
}
23+
public record RepeatSequence : IGetNext<RepeatSequence>
24+
{
25+
private const char Ch = 'A';
26+
public string Text = new string(Ch, 1);
27+
28+
public static RepeatSequence Next(RepeatSequence other) => other with { Text = other.Text + Ch };
29+
30+
public override string ToString() => Text;
31+
}
32+
33+
}""" |> withCSharpLanguageVersion CSharpLanguageVersion.Preview |> withName "csLib"
34+
35+
36+
#if !NETCOREAPP
37+
[<Fact(Skip = "NET472 is unsupported runtime for this kind of test.")>]
38+
#else
39+
[<Fact>]
40+
#endif
41+
let ``F# can call static methods declared in interfaces from C#`` () =
42+
43+
let csharpLib = csharpBaseClass
44+
45+
let fsharpSource =
46+
"""
47+
open System
48+
open StaticsInInterfaces
49+
50+
[<EntryPoint>]
51+
let main _ =
52+
53+
let mutable str = RepeatSequence ()
54+
let res = [ for i in 0..10 do
55+
yield string(str)
56+
str <- RepeatSequence.Next(str) ]
57+
58+
if res <> ["A"; "AA"; "AAA"; "AAAA"; "AAAAA"; "AAAAAA"; "AAAAAAA"; "AAAAAAAA"; "AAAAAAAAA"; "AAAAAAAAAA"; "AAAAAAAAAAA"] then
59+
failwith $"Unexpected result: %A{res}"
60+
61+
if string(str) <> "AAAAAAAAAAAA" then
62+
failwith $"Unexpected result %s{string(str)}"
63+
0
64+
"""
65+
FSharp fsharpSource
66+
|> asExe
67+
|> withLangVersionPreview
68+
|> withReferences [csharpLib]
69+
|> compileAndRun
70+
|> shouldSucceed
71+
// TODO: test operators, test implementing statics.

tests/FSharp.Test.Utilities/Compiler.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ module rec Compiler =
580580
let lv =
581581
match csSource.LangVersion with
582582
| CSharpLanguageVersion.CSharp8 -> LanguageVersion.CSharp8
583+
| CSharpLanguageVersion.CSharp9 -> LanguageVersion.CSharp9
584+
| CSharpLanguageVersion.Preview -> LanguageVersion.Preview
583585
| _ -> LanguageVersion.Default
584586

585587
let cmpl =

tests/FSharp.Test.Utilities/CompilerAssert.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ type TestCompilation =
130130
type CSharpLanguageVersion =
131131
| CSharp8 = 0
132132
| CSharp9 = 1
133+
| Preview = 99
133134

134135
[<AbstractClass; Sealed>]
135136
type CompilationUtil private () =
@@ -139,6 +140,7 @@ type CompilationUtil private () =
139140
match lv with
140141
| CSharpLanguageVersion.CSharp8 -> LanguageVersion.CSharp8
141142
| CSharpLanguageVersion.CSharp9 -> LanguageVersion.CSharp9
143+
| CSharpLanguageVersion.Preview -> LanguageVersion.Preview
142144
| _ -> LanguageVersion.Default
143145

144146
let tf = defaultArg tf TargetFramework.NetStandard20

tests/FSharp.Test.Utilities/TestFramework.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ let config configurationName envVars =
316316
let packagesDir = getPackagesDir ()
317317
let requirePackage = requireFile packagesDir
318318
let requireArtifact = requireFile artifactsBinPath
319-
let CSC = requirePackage ("Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "csc.exe")
320-
let VBC = requirePackage ("Microsoft.Net.Compilers" ++ "2.7.0" ++ "tools" ++ "vbc.exe")
319+
let CSC = requirePackage ("Microsoft.Net.Compilers" ++ "4.3.0-1.22220.8" ++ "tools" ++ "csc.exe")
320+
let VBC = requirePackage ("Microsoft.Net.Compilers" ++ "4.3.0-1.22220.8" ++ "tools" ++ "vbc.exe")
321321
let ILDASM_EXE = if operatingSystem = "win" then "ildasm.exe" else "ildasm"
322322
let ILDASM = requirePackage (("runtime." + operatingSystem + "-" + architectureMoniker + ".Microsoft.NETCore.ILDAsm") ++ coreClrRuntimePackageVersion ++ "runtimes" ++ (operatingSystem + "-" + architectureMoniker) ++ "native" ++ ILDASM_EXE)
323323
let ILASM_EXE = if operatingSystem = "win" then "ilasm.exe" else "ilasm"

tests/fsharpqa/run.fsharpqa.test.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let nugetCache =
2323
| path -> path
2424
let rootFolder = Path.Combine(__SOURCE_DIRECTORY__, "..", "..")
2525
let compilerBinFolder = Path.Combine(rootFolder, "artifacts", "bin", "fsc", releaseOrDebug, "net472")
26-
setEnvVar "CSC_PIPE" (Path.Combine(nugetCache, "Microsoft.Net.Compilers", "2.7.0", "tools", "csc.exe"))
26+
setEnvVar "CSC_PIPE" (Path.Combine(nugetCache, "Microsoft.Net.Compilers", "4.3.0-1.22220.8", "tools", "csc.exe"))
2727
setEnvVar "FSC" (Path.Combine(compilerBinFolder, "fsc.exe"))
2828
setEnvVar "FSCOREDLLPATH" (Path.Combine(compilerBinFolder, "FSharp.Core.dll"))
2929
addToPath compilerBinFolder

vsintegration/src/FSharp.ProjectSystem.PropertyPages/FSharp.ProjectSystem.PropertyPages.vbproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="$(MicrosoftVisualStudioShell150Version)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
5353
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="$(MicrosoftVisualStudioThreadingVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
5454
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
55-
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" PrivateAssets="all" ExcludeAssets="runtime;contentFiles;build;analyzers;native" />
5655
</ItemGroup>
5756

5857
<ItemGroup>

vsintegration/tests/UnitTests/VisualFSharp.UnitTests.fsproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@
194194
<PackageReference Include="Microsoft.VisualStudio.Utilities" Version="$(MicrosoftVisualStudioUtilitiesVersion)" />
195195
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="$(MicrosoftVisualStudioValidationVersion)" />
196196
<PackageReference Include="Nerdbank.Streams" Version="$(NerdbankStreamsVersion)" />
197-
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
198197
<PackageReference Include="StreamJsonRpc" Version="$(StreamJsonRpcVersion)" />
199198
</ItemGroup>
200199

0 commit comments

Comments
 (0)