Skip to content

Commit 14b775c

Browse files
ncaveforki
authored andcommitted
Added some tests (#40)
* Add option to toggle unused declarations analyzer (dotnet#4074) * Add option to toggle unused declarations analyzer * Better name and handle registering code fixes. This will ensure that if someone uses warnon:1182, we won't suggest fixes if they've turned off the feature. * Revert dotnet#1650 (and dotnet#3366) (dotnet#4173) * Fix error logging in brace matching code (dotnet#4140) * Remove error logger pushing code * Update service.fs * Fix dotnet#4200: Vsix: fix empty "New file" window for web projects (dotnet#4202) * LOC CHECKIN | visualfsharp - master | 20180112 (dotnet#4194) * Fixed FCS netcore tests (dotnet#4180) * Remove ambiguous resolution error FS0332 (dotnet#4170) * Add IsInteractive to parsing options for script load closures (dotnet#4169) * Add IsInteractive to FSharpParsingOptions * Add test * Set serializable bit for all serializable types (dotnet#4211) * Minor fix (dotnet#4195) on string 58. * Symbols API: add Index to active pattern case, Name to pattern group (dotnet#4222) * Symbols API: add Index to active pattern case, Name to pattern group * Symbols API: add active pattern case use tests * don't rebuild (dotnet#4230) * Optimize in FCS * Transport tcConfig * Cleanup * Replace more ILAsm in Exprs * More ILAsm replacements * update resource name * Added some tests
1 parent c9ce53f commit 14b775c

File tree

87 files changed

+620
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+620
-254
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,5 @@ tests/fsharpqa/testenv/bin/System.ValueTuple.dll
125125
/tests/fcs/
126126
/fcs/.paket/Paket.Restore.targets
127127
msbuild.binlog
128+
/fcs/FSharp.Compiler.Service.netstandard/*.fs
129+
/fcs/FSharp.Compiler.Service.netstandard/*.fsi

TESTGUIDE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ For the FSharpQA suite, the list of test areas and their associated "tags" is st
5555

5656
tests\fsharpqa\source\test.lst // FSharpQA suite
5757

58-
Tags are in the left column, paths to to corresponding test folders are in the right column. If no tags are specifie, all tests will be run.
58+
Tags are in the left column, paths to to corresponding test folders are in the right column. If no tags are specified, all tests will be run.
5959

6060
If you want to re-run a particular test area, the easiest way to do so is to set a temporary tag for that area in test.lst (e.g. "RERUN") and then pass that as an argument to `build.cmd`: `build.cmd test-net40-fsharpqa include RERUN`.
6161

@@ -65,7 +65,7 @@ These are all NUnit tests. You can execute these tests individually via the Visu
6565
extension or the command line via `nunit3-console.exe`.
6666

6767
Note that for compatibility reasons, the IDE unit tests should be run in a 32-bit process,
68-
using the '--x86' flag to `nunit3-console.exe`
68+
using the `--x86` flag to `nunit3-console.exe`
6969

7070

7171

fcs/FSharp.Compiler.Service.Tests.netcore/FSharp.Compiler.Service.Tests.netcore.fsproj

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp1.0</TargetFramework>
4-
<DefineConstants>$(DefineConstants);DOTNETCORE;FX_ATLEAST_45;FX_ATLEAST_PORTABLE;FX_NO_RUNTIMEENVIRONMENT;FX_RESHAPED_REFLECTION;TODO_REWORK_ASSEMBLY_LOAD;</DefineConstants>
3+
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<DefineConstants>$(DefineConstants);DOTNETCORE</DefineConstants>
5+
<DefineConstants>$(DefineConstants);FX_ATLEAST_45</DefineConstants>
6+
<DefineConstants>$(DefineConstants);FX_ATLEAST_PORTABLE</DefineConstants>
7+
<DefineConstants>$(DefineConstants);FX_NO_RUNTIMEENVIRONMENT</DefineConstants>
8+
<DefineConstants>$(DefineConstants);FX_RESHAPED_REFLECTION</DefineConstants>
9+
<DefineConstants>$(DefineConstants);NO_EXTENSIONTYPING</DefineConstants>
10+
<DefineConstants>$(DefineConstants);TODO_REWORK_ASSEMBLY_LOAD</DefineConstants>
511
<NoWarn>$(NoWarn);44;</NoWarn>
612
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
713
<DelaySign>true</DelaySign>
@@ -36,25 +42,21 @@
3642
<!--<Compile Include="../service/ProjectAnalysisTests.fs">
3743
<Link>ProjectAnalysisTests.fs</Link>
3844
</Compile>-->
45+
<Compile Include="../../tests/service/Program.fs">
46+
<Link>Program.fs</Link>
47+
</Compile>
3948
</ItemGroup>
4049
<ItemGroup>
4150
<ProjectReference Include="../FSharp.Compiler.Service.netstandard/FSharp.Compiler.Service.netstandard.fsproj" />
4251
</ItemGroup>
4352
<ItemGroup>
44-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
45-
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
46-
<PackageReference Include="NUnitLite" Version="3.6.1" />
47-
<PackageReference Include="NUnit" Version="3.6.1" />
48-
<PackageReference Include="FSharp.Core" Version="4.1.*" PrivateAssets="All" />
49-
<PackageReference Include="System.Runtime" Version="4.3.0" />
50-
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
51-
<PackageReference Include="System.Reflection.Metadata" Version="1.4.1" />
52-
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
53-
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
54-
<PackageReference Include="Dotnet.ProjInfo" Version="0.5.0" />
53+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
54+
<PackageReference Include="NUnit" Version="3.9.0" />
55+
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
56+
<PackageReference Include="Dotnet.ProjInfo" Version="0.9.0" />
5557
</ItemGroup>
5658
<Target Name="PrecompileScript" BeforeTargets="BeforeBuild">
57-
<Exec Command="dotnet restore &quot;$(MSBuildProjectDirectory)/../../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard1.6/Sample_NETCoreSDK_FSharp_Library_netstandard1.6.fsproj&quot;" />
58-
<Exec Command="dotnet build &quot;$(MSBuildProjectDirectory)/../../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard1.6/Sample_NETCoreSDK_FSharp_Library_netstandard1.6.fsproj&quot;" />
59+
<Exec Command="dotnet restore &quot;$(MSBuildProjectDirectory)/../../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard2_0/Sample_NETCoreSDK_FSharp_Library_netstandard2_0.fsproj&quot;" />
60+
<Exec Command="dotnet build &quot;$(MSBuildProjectDirectory)/../../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard2_0/Sample_NETCoreSDK_FSharp_Library_netstandard2_0.fsproj&quot;" />
5961
</Target>
6062
</Project>

fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<Compile Include="$(FSharpSourcesRoot)\..\tests\service\EditorTests.fs">
4747
<Link>EditorTests.fs</Link>
4848
</Compile>
49+
<Compile Include="$(FSharpSourcesRoot)\..\tests\service\Symbols.fs">
50+
<Link>Symbols.fs</Link>
51+
</Compile>
4952
<Compile Include="$(FSharpSourcesRoot)\..\tests\service\FileSystemTests.fs">
5053
<Link>FileSystemTests.fs</Link>
5154
</Compile>

src/fsharp/ConstraintSolver.fs

+24-34
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ let ShowAccessDomain ad =
370370
// Solve
371371

372372
exception NonRigidTypar of DisplayEnv * string option * range * TType * TType * range
373-
exception LocallyAbortOperationThatFailsToResolveOverload
374373
exception LocallyAbortOperationThatLosesAbbrevs
375374
let localAbortD = ErrorD LocallyAbortOperationThatLosesAbbrevs
376375

@@ -739,19 +738,19 @@ and solveTypMeetsTyparConstraints (csenv:ConstraintSolverEnv) ndeep m2 trace ty
739738
| Some destTypar ->
740739
AddConstraint csenv ndeep m2 trace destTypar (TyparConstraint.DefaultsTo(priority, dty, m))
741740

742-
| TyparConstraint.SupportsNull m2 -> SolveTypSupportsNull csenv ndeep m2 trace ty
743-
| TyparConstraint.IsEnum(underlying, m2) -> SolveTypIsEnum csenv ndeep m2 trace ty underlying
744-
| TyparConstraint.SupportsComparison(m2) -> SolveTypeSupportsComparison csenv ndeep m2 trace ty
745-
| TyparConstraint.SupportsEquality(m2) -> SolveTypSupportsEquality csenv ndeep m2 trace ty
741+
| TyparConstraint.SupportsNull m2 -> SolveTypSupportsNull csenv ndeep m2 trace ty
742+
| TyparConstraint.IsEnum(underlying, m2) -> SolveTypIsEnum csenv ndeep m2 trace ty underlying
743+
| TyparConstraint.SupportsComparison(m2) -> SolveTypeSupportsComparison csenv ndeep m2 trace ty
744+
| TyparConstraint.SupportsEquality(m2) -> SolveTypSupportsEquality csenv ndeep m2 trace ty
746745
| TyparConstraint.IsDelegate(aty, bty, m2) -> SolveTypIsDelegate csenv ndeep m2 trace ty aty bty
747-
| TyparConstraint.IsNonNullableStruct m2 -> SolveTypIsNonNullableValueType csenv ndeep m2 trace ty
748-
| TyparConstraint.IsUnmanaged m2 -> SolveTypIsUnmanaged csenv ndeep m2 trace ty
749-
| TyparConstraint.IsReferenceType m2 -> SolveTypIsReferenceType csenv ndeep m2 trace ty
750-
| TyparConstraint.RequiresDefaultConstructor m2 -> SolveTypRequiresDefaultConstructor csenv ndeep m2 trace ty
746+
| TyparConstraint.IsNonNullableStruct m2 -> SolveTypIsNonNullableValueType csenv ndeep m2 trace ty
747+
| TyparConstraint.IsUnmanaged m2 -> SolveTypIsUnmanaged csenv ndeep m2 trace ty
748+
| TyparConstraint.IsReferenceType m2 -> SolveTypIsReferenceType csenv ndeep m2 trace ty
749+
| TyparConstraint.RequiresDefaultConstructor m2 -> SolveTypRequiresDefaultConstructor csenv ndeep m2 trace ty
751750
| TyparConstraint.SimpleChoice(tys, m2) -> SolveTypChoice csenv ndeep m2 trace ty tys
752751
| TyparConstraint.CoercesTo(ty2, m2) -> SolveTypSubsumesTypKeepAbbrevs csenv ndeep m2 trace None ty2 ty
753-
| TyparConstraint.MayResolveMember(traitInfo, m2) ->
754-
SolveMemberConstraint csenv false false ndeep m2 trace traitInfo ++ (fun _ -> CompleteD)
752+
| TyparConstraint.MayResolveMember(traitInfo, m2) ->
753+
SolveMemberConstraint csenv false ndeep m2 trace traitInfo ++ (fun _ -> CompleteD)
755754
)))
756755

757756

@@ -761,15 +760,14 @@ and SolveTypEqualsTyp (csenv:ConstraintSolverEnv) ndeep m2 (trace: OptionalTrace
761760
let ndeep = ndeep + 1
762761
let aenv = csenv.EquivEnv
763762
let g = csenv.g
763+
if ty1 === ty2 then CompleteD else
764764

765765
match cxsln with
766766
| Some (traitInfo, traitSln) when traitInfo.Solution.IsNone ->
767767
// If this is an overload resolution at this point it's safe to assume the candidate member being evaluated solves this member constraint.
768768
TransactMemberConstraintSolution traitInfo trace traitSln
769769
| _ -> ()
770770

771-
if ty1 === ty2 then CompleteD else
772-
773771
let canShortcut = not trace.HasTrace
774772
let sty1 = stripTyEqnsA csenv.g canShortcut ty1
775773
let sty2 = stripTyEqnsA csenv.g canShortcut ty2
@@ -943,7 +941,7 @@ and SolveDimensionlessNumericType (csenv:ConstraintSolverEnv) ndeep m2 trace ty
943941
/// We pretend int and other types support a number of operators. In the actual IL for mscorlib they
944942
/// don't, however the type-directed static optimization rules in the library code that makes use of this
945943
/// will deal with the problem.
946-
and SolveMemberConstraint (csenv:ConstraintSolverEnv) ignoreUnresolvedOverload permitWeakResolution ndeep m2 trace (TTrait(tys, nm, memFlags, argtys, rty, sln)): OperationResult<bool> =
944+
and SolveMemberConstraint (csenv:ConstraintSolverEnv) permitWeakResolution ndeep m2 trace (TTrait(tys,nm,memFlags,argtys,rty,sln)) : OperationResult<bool> =
947945
// Do not re-solve if already solved
948946
if sln.Value.IsSome then ResultD true else
949947
let g = csenv.g
@@ -1300,12 +1298,9 @@ and SolveMemberConstraint (csenv:ConstraintSolverEnv) ignoreUnresolvedOverload p
13001298
let frees = GetFreeTyparsOfMemberConstraint csenv traitInfo
13011299

13021300
// If there's nothing left to learn then raise the errors
1303-
(if (permitWeakResolution && isNil support) || isNil frees then errors
1304-
// Otherwise re-record the trait waiting for canonicalization
1305-
else AddMemberConstraint csenv ndeep m2 trace traitInfo support frees) ++ (fun () ->
1306-
match errors with
1307-
| ErrorResult (_, UnresolvedOverloading _) when not ignoreUnresolvedOverload && (not (nm = "op_Explicit" || nm = "op_Implicit")) -> ErrorD LocallyAbortOperationThatFailsToResolveOverload
1308-
| _ -> ResultD TTraitUnsolved)
1301+
(if (permitWeakResolution && isNil support) || isNil frees then errors
1302+
// Otherwise re-record the trait waiting for canonicalization
1303+
else AddMemberConstraint csenv ndeep m2 trace traitInfo support frees) ++ (fun () -> ResultD TTraitUnsolved)
13091304
)
13101305
++
13111306
(fun res -> RecordMemberConstraintSolution csenv.SolverState m trace traitInfo res))
@@ -1447,7 +1442,7 @@ and SolveRelevantMemberConstraintsForTypar (csenv:ConstraintSolverEnv) ndeep per
14471442
cxs
14481443
|> AtLeastOneD (fun (traitInfo, m2) ->
14491444
let csenv = { csenv with m = m2 }
1450-
SolveMemberConstraint csenv true permitWeakResolution (ndeep+1) m2 trace traitInfo)
1445+
SolveMemberConstraint csenv permitWeakResolution (ndeep+1) m2 trace traitInfo)
14511446

14521447
and CanonicalizeRelevantMemberConstraints (csenv:ConstraintSolverEnv) ndeep trace tps =
14531448
SolveRelevantMemberConstraints csenv ndeep true trace tps
@@ -1962,22 +1957,18 @@ and CanMemberSigsMatchUpToCheck
19621957
// to allow us to report the outer types involved in the constraint
19631958
and private SolveTypSubsumesTypWithReport (csenv:ConstraintSolverEnv) ndeep m trace cxsln ty1 ty2 =
19641959
TryD (fun () -> SolveTypSubsumesTypKeepAbbrevs csenv ndeep m trace cxsln ty1 ty2)
1965-
(function
1966-
| LocallyAbortOperationThatFailsToResolveOverload -> CompleteD
1967-
| res ->
1968-
match csenv.eContextInfo with
1969-
| ContextInfo.RuntimeTypeTest isOperator ->
1970-
// test if we can cast other way around
1960+
(fun res ->
1961+
match csenv.eContextInfo with
1962+
| ContextInfo.RuntimeTypeTest isOperator ->
1963+
// test if we can cast other way around
19711964
match CollectThenUndo (fun newTrace -> SolveTypSubsumesTypKeepAbbrevs csenv ndeep m (OptionalTrace.WithTrace newTrace) cxsln ty2 ty1) with
19721965
| OkResult _ -> ErrorD (ErrorsFromAddingSubsumptionConstraint(csenv.g, csenv.DisplayEnv, ty1, ty2, res, ContextInfo.DowncastUsedInsteadOfUpcast isOperator, m))
19731966
| _ -> ErrorD (ErrorsFromAddingSubsumptionConstraint(csenv.g, csenv.DisplayEnv, ty1, ty2, res, ContextInfo.NoContext, m))
19741967
| _ -> ErrorD (ErrorsFromAddingSubsumptionConstraint(csenv.g, csenv.DisplayEnv, ty1, ty2, res, csenv.eContextInfo, m)))
19751968

19761969
and private SolveTypEqualsTypWithReport (csenv:ConstraintSolverEnv) ndeep m trace cxsln ty1 ty2 =
19771970
TryD (fun () -> SolveTypEqualsTypKeepAbbrevsWithCxsln csenv ndeep m trace cxsln ty1 ty2)
1978-
(function
1979-
| LocallyAbortOperationThatFailsToResolveOverload -> CompleteD
1980-
| res -> ErrorD (ErrorFromAddingTypeEquation(csenv.g, csenv.DisplayEnv, ty1, ty2, res, m)))
1971+
(fun res -> ErrorD (ErrorFromAddingTypeEquation(csenv.g, csenv.DisplayEnv, ty1, ty2, res, m)))
19811972

19821973
and ArgsMustSubsumeOrConvert
19831974
(csenv:ConstraintSolverEnv)
@@ -2543,7 +2534,7 @@ let AddCxTypeMustSubsumeType contextInfo denv css m trace ty1 ty2 =
25432534
|> RaiseOperationResult
25442535

25452536
let AddCxMethodConstraint denv css m trace traitInfo =
2546-
TryD (fun () -> SolveMemberConstraint (MakeConstraintSolverEnv ContextInfo.NoContext css m denv) true false 0 m trace traitInfo ++ (fun _ -> CompleteD))
2537+
TryD (fun () -> SolveMemberConstraint (MakeConstraintSolverEnv ContextInfo.NoContext css m denv) false 0 m trace traitInfo ++ (fun _ -> CompleteD))
25472538
(fun res -> ErrorD (ErrorFromAddingConstraint(denv, res, m)))
25482539
|> RaiseOperationResult
25492540

@@ -2601,7 +2592,7 @@ let CodegenWitnessThatTypSupportsTraitConstraint tcVal g amap m (traitInfo:Trait
26012592
InfoReader = new InfoReader(g, amap) }
26022593

26032594
let csenv = MakeConstraintSolverEnv ContextInfo.NoContext css m (DisplayEnv.Empty g)
2604-
SolveMemberConstraint csenv true true 0 m NoTrace traitInfo ++ (fun _res ->
2595+
SolveMemberConstraint csenv true 0 m NoTrace traitInfo ++ (fun _res ->
26052596
let sln =
26062597
match traitInfo.Solution with
26072598
| None -> Choice4Of4()
@@ -2725,5 +2716,4 @@ let IsApplicableMethApprox g amap m (minfo:MethInfo) availObjTy =
27252716
|> CommitOperationResult
27262717
| _ -> true
27272718
else
2728-
true
2729-
2719+
true

src/fsharp/FSComp.txt

-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ FieldNotContainedMutablesDiffer,"The module contains the field\n %s \nbut
161161
FieldNotContainedLiteralsDiffer,"The module contains the field\n %s \nbut its signature specifies\n %s \nThe 'literal' modifiers differ"
162162
FieldNotContainedTypesDiffer,"The module contains the field\n %s \nbut its signature specifies\n %s \nThe types differ"
163163
331,typrelCannotResolveImplicitGenericInstantiation,"The implicit instantiation of a generic construct at or near this point could not be resolved because it could resolve to multiple unrelated types, e.g. '%s' and '%s'. Consider using type annotations to resolve the ambiguity"
164-
332,typrelCannotResolveAmbiguityInOverloadedOperator,"Could not resolve the ambiguity inherent in the use of the operator '%s' at or near this program point. Consider using type annotations to resolve the ambiguity."
165164
333,typrelCannotResolveAmbiguityInPrintf,"Could not resolve the ambiguity inherent in the use of a 'printf'-style format string"
166165
334,typrelCannotResolveAmbiguityInEnum,"Could not resolve the ambiguity in the use of a generic construct with an 'enum' constraint at or near this position"
167166
335,typrelCannotResolveAmbiguityInDelegate,"Could not resolve the ambiguity in the use of a generic construct with a 'delegate' constraint at or near this position"

src/fsharp/FSharp.Build/WriteCodeFragment.fs

+7-3
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,19 @@ open System.Reflection"
113113
let sb = StringBuilder().AppendLine(boilerplate).AppendLine()
114114
let code = Array.fold (fun (sb:StringBuilder) (item:ITaskItem) -> sb.AppendLine(WriteCodeFragment.GenerateAttribute item)) sb _assemblyAttributes
115115
code.AppendLine().AppendLine("do()") |> ignore
116+
let fileName = _outputFile.ItemSpec
116117
let outputFileItem =
117-
if not (isNull _outputFile) && not (isNull _outputDirectory) && not (Path.IsPathRooted(_outputFile.ItemSpec)) then
118-
TaskItem(Path.Combine(_outputDirectory.ItemSpec, _outputFile.ItemSpec)) :> ITaskItem
118+
if not (isNull _outputFile) && not (isNull _outputDirectory) && not (Path.IsPathRooted(fileName)) then
119+
TaskItem(Path.Combine(_outputDirectory.ItemSpec, fileName)) :> ITaskItem
119120
elif isNull _outputFile then
120121
let tempFile = Path.Combine(Path.GetTempPath(), sprintf "tmp%s.fs" (Guid.NewGuid().ToString("N")))
121122
TaskItem(tempFile) :> ITaskItem
122123
else
123124
_outputFile
124-
File.WriteAllText(_outputFile.ItemSpec, code.ToString())
125+
let codeText = code.ToString()
126+
let alreadyExists = (try File.Exists fileName && File.ReadAllText(fileName) = codeText with _ -> false)
127+
if not alreadyExists then
128+
File.WriteAllText(fileName, codeText)
125129
_outputFile <- outputFileItem
126130
true
127131
with e ->

0 commit comments

Comments
 (0)