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: 0 additions & 2 deletions tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup Condition="'$(UnitTestType)' == 'nunit'">
<!-- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" /> -->
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<PackageReference Include="NUnit3TestAdapter" Version="$(NUnit3TestAdapterVersion)" />
<PackageReference Include="NunitXml.TestLogger" Version="$(NunitXmlTestLoggerVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(UnitTestType)' == 'xunit'">
<!-- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" /> -->
<PackageReference Include="xunit" Version="$(XUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitVersion)" />
<PackageReference Include="NunitXml.TestLogger" Version="$(NunitXmlTestLoggerVersion)" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.ErrorMessages.ComponentTests

open Xunit
open FSharp.Test.Utilities
open FSharp.Compiler.SourceCodeServices

module ``Access Of Type Abbreviation`` =

[<Fact>]
let ``Private type produces warning when trying to export``() =
CompilerAssert.TypeCheckSingleError
"""
module Library =
type private Hidden = Hidden of unit
type Exported = Hidden
"""
FSharpErrorSeverity.Warning
44
(4, 8, 4, 16)
("This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors.")

[<Fact>]
let ``Internal type passes when abbrev is internal``() =
CompilerAssert.Pass
"""
module Library =
type internal Hidden = Hidden of unit
type internal Exported = Hidden
"""

[<Fact>]
let ``Internal type produces warning when trying to export``() =
CompilerAssert.TypeCheckSingleError
"""
module Library =
type internal Hidden = Hidden of unit
type Exported = Hidden
"""
FSharpErrorSeverity.Warning
44
(4, 8, 4, 16)
("This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors.")

[<Fact>]
let ``Private type produces warning when abbrev is internal``() =
CompilerAssert.TypeCheckSingleError
"""
module Library =
type private Hidden = Hidden of unit
type internal Exported = Hidden
"""
FSharpErrorSeverity.Warning
44
(4, 17, 4, 25)
("This construct is deprecated. The type 'Hidden' is less accessible than the value, member or type 'Exported' it is used in." + System.Environment.NewLine + "As of F# 4.1, the accessibility of type abbreviations is checked at compile-time. Consider changing the accessibility of the type abbreviation. Ignoring this warning might lead to runtime errors.")

[<Fact>]
let ``Private type passes when abbrev is private``() =
CompilerAssert.Pass
"""
module Library =
type private Hidden = Hidden of unit
type private Exported = Hidden
"""

[<Fact>]
let ``Default access type passes when abbrev is default``() =
CompilerAssert.Pass
"""
module Library =
type Hidden = Hidden of unit
type Exported = Hidden
"""
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests
namespace FSharp.Compiler.ErrorMessages.ComponentTests

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

[<TestFixture>]

module ``Errors assigning to mutable objects`` =

[<Test>]
[<Fact>]
let ``Assign to immutable error``() =
CompilerAssert.TypeCheckSingleError
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests
namespace FSharp.Compiler.ErrorMessages.ComponentTests

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

[<TestFixture>]
module ``Classes`` =

[<Test>]
[<Fact>]
let ``Tuple In Abstract Method``() =
CompilerAssert.TypeCheckWithErrors
"""
Expand All @@ -27,7 +26,7 @@ let x =
FSharpErrorSeverity.Error, 783, (6, 9, 6, 19), "At least one override did not correctly implement its corresponding abstract member"
|]

[<Test>]
[<Fact>]
let ``Wrong Arity``() =
CompilerAssert.TypeCheckSingleError
"""
Expand All @@ -43,7 +42,7 @@ MyType.MyMember("", 0, 0)
(7, 1, 7, 26)
"A member or object constructor 'MyMember' taking 3 arguments is not accessible from this code location. All accessible versions of method 'MyMember' take 2 arguments."

[<Test>]
[<Fact>]
let ``Method Is Not Static``() =
CompilerAssert.TypeCheckSingleError
"""
Expand All @@ -57,7 +56,7 @@ let x = Class1.X()
(5, 9, 5, 17)
"Method or object constructor 'X' is not static"

[<Test>]
[<Fact>]
let ``Matching Method With Same Name Is Not Abstract``() =
CompilerAssert.TypeCheckWithErrors
"""
Expand All @@ -75,7 +74,7 @@ let foo =
FSharpErrorSeverity.Error, 783, (6, 11, 6, 14), "At least one override did not correctly implement its corresponding abstract member"
|]

[<Test>]
[<Fact>]
let ``No Matching Abstract Method With Same Name``() =
CompilerAssert.TypeCheckWithErrors
"""
Expand All @@ -89,13 +88,13 @@ let x =
}
"""
[|
FSharpErrorSeverity.Error, 767, (8, 14, 8, 34), "The member 'Function' does not correspond to any abstract or virtual method available to override or implement. Maybe you want one of the following:\r\n MyFunction"
FSharpErrorSeverity.Error, 767, (8, 14, 8, 34), "The member 'Function' does not correspond to any abstract or virtual method available to override or implement. Maybe you want one of the following:" + System.Environment.NewLine + " MyFunction"
FSharpErrorSeverity.Error, 17, (8, 19, 8, 27), "The member 'Function : 'a * 'b -> unit' does not have the correct type to override any given virtual method"
FSharpErrorSeverity.Error, 366, (7, 3, 9, 4), "No implementation was given for those members: \r\n\t'abstract member IInterface.MyFunction : int32 * int32 -> unit'\r\n\t'abstract member IInterface.SomeOtherFunction : int32 * int32 -> unit'\r\nNote that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'."
FSharpErrorSeverity.Error, 366, (7, 3, 9, 4), "No implementation was given for those members: " + System.Environment.NewLine + "\t'abstract member IInterface.MyFunction : int32 * int32 -> unit'" + System.Environment.NewLine + "\t'abstract member IInterface.SomeOtherFunction : int32 * int32 -> unit'" + System.Environment.NewLine + "Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'."
FSharpErrorSeverity.Error, 783, (7, 9, 7, 19), "At least one override did not correctly implement its corresponding abstract member"
|]

[<Test>]
[<Fact>]
let ``Member Has Multiple Possible Dispatch Slots``() =
CompilerAssert.TypeCheckWithErrors
"""
Expand All @@ -108,11 +107,11 @@ type Overload =
override __.Bar _ = 1
"""
[|
FSharpErrorSeverity.Error, 366, (7, 15, 7, 24), "No implementation was given for those members: \r\n\t'abstract member IOverload.Bar : double -> int'\r\n\t'abstract member IOverload.Bar : int -> int'\r\nNote that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'."
FSharpErrorSeverity.Error, 3213, (8, 21, 8, 24), "The member 'Bar<'a0> : 'a0 -> int' matches multiple overloads of the same method.\nPlease restrict it to one of the following:\r\n Bar : double -> int\r\n Bar : int -> int."
FSharpErrorSeverity.Error, 366, (7, 15, 7, 24), "No implementation was given for those members: " + System.Environment.NewLine + "\t'abstract member IOverload.Bar : double -> int'" + System.Environment.NewLine + "\t'abstract member IOverload.Bar : int -> int'" + System.Environment.NewLine + "Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g. 'interface ... with member ...'."
FSharpErrorSeverity.Error, 3213, (8, 21, 8, 24), "The member 'Bar<'a0> : 'a0 -> int' matches multiple overloads of the same method.\nPlease restrict it to one of the following:" + System.Environment.NewLine + " Bar : double -> int" + System.Environment.NewLine + " Bar : int -> int."
|]

[<Test>]
[<Fact>]
let ``Do Cannot Have Visibility Declarations``() =
CompilerAssert.ParseWithErrors
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.ErrorMessages.ComponentTests

open Xunit
open FSharp.Test.Utilities
open FSharp.Test.Utilities.Utilities
open FSharp.Compiler.SourceCodeServices

module ``Confusing Type Name`` =

[<Fact>]
let ``Checks expected types with multiple references``() =
let csLibAB = """
public class A { }
public class B<T> { }
"""
let csLibACmpl =
CompilationUtil.CreateCSharpCompilation(csLibAB, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30, name = "libA")
|> CompilationReference.Create

let csLibBCmpl =
CompilationUtil.CreateCSharpCompilation(csLibAB, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30, name = "libB")
|> CompilationReference.Create

let fsLibC = """
module AMaker
let makeA () : A = A()
let makeB () = B<_>()
"""

let fsLibD = """
module OtherAMaker
let makeOtherA () : A = A()
let makeOtherB () = B<_>()
"""

let fsLibCCmpl =
Compilation.Create(fsLibC, Fs, Library, cmplRefs = [csLibACmpl], name = "libC")
|> CompilationReference.CreateFSharp

let fsLibDCmpl =
Compilation.Create(fsLibD, Fs, Library, cmplRefs = [csLibBCmpl], name = "libD")
|> CompilationReference.CreateFSharp

let app = """
module ConfusingTypeName
let a = AMaker.makeA()
let otherA = OtherAMaker.makeOtherA()
printfn "%A %A" (a.GetType().AssemblyQualifiedName) (otherA.GetType().AssemblyQualifiedName)
printfn "%A" (a = otherA)

let b = AMaker.makeB<int>()
let otherB = OtherAMaker.makeOtherB<int>()
printfn "%A %A" (b.GetType().AssemblyQualifiedName) (otherB.GetType().AssemblyQualifiedName)
printfn "%A" (b = otherB)
"""

let appCmpl =
Compilation.Create(app, Fs, Library, cmplRefs = [csLibACmpl; csLibBCmpl; fsLibCCmpl; fsLibDCmpl])

CompilerAssert.CompileWithErrors(
appCmpl,
[|
(FSharpErrorSeverity.Error, 1, (6, 19, 6, 25), ("This expression was expected to have type\n 'A (libA, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' \nbut here has type\n 'A (libB, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' "))
(FSharpErrorSeverity.Error, 1, (11, 19, 11, 25), ("This expression was expected to have type\n 'B<Microsoft.FSharp.Core.int> (libA, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' \nbut here has type\n 'B<Microsoft.FSharp.Core.int> (libB, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)' "))
|], true)
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests
namespace FSharp.Compiler.ErrorMessages.ComponentTests

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

[<TestFixture>]
module ``Constructor`` =

[<Test>]
[<Fact>]
let ``Invalid Record``() =
CompilerAssert.TypeCheckWithErrors
"""
type Record = {field1:int; field2:int}
let doSomething (xs) = List.map (fun {field1=x} -> x) xs

doSomething {Record.field1=0; field2=0}
"""
[|
FSharpErrorSeverity.Error, 1, (5, 13, 5, 40), "This expression was expected to have type\n 'Record list' \nbut here has type\n 'Record' "
FSharpErrorSeverity.Warning, 20, (5, 1, 5, 40), "The result of this expression has type 'int list' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'."
FSharpErrorSeverity.Error, 1, (4, 13, 4, 40), "This expression was expected to have type\n 'Record list' \nbut here has type\n 'Record' "
FSharpErrorSeverity.Warning, 20, (4, 1, 4, 40), "The result of this expression has type 'int list' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'."
|]

[<Test>]
[<Fact>]
let ``Comma In Rec Ctor``() =
CompilerAssert.TypeCheckWithErrors
"""
type Person = { Name : string; Age : int; City : string }
let x = { Name = "Isaac", Age = 21, City = "London" }
"""
[|
FSharpErrorSeverity.Error, 1, (3, 18, 3, 52), "This expression was expected to have type\n 'string' \nbut here has type\n ''a * 'b * 'c' \r\nA ';' is used to separate field values in records. Consider replacing ',' with ';'."
FSharpErrorSeverity.Error, 1, (3, 18, 3, 52), "This expression was expected to have type\n 'string' \nbut here has type\n ''a * 'b * 'c' " + System.Environment.NewLine + "A ';' is used to separate field values in records. Consider replacing ',' with ';'."
FSharpErrorSeverity.Error, 764, (3, 9, 3, 54), "No assignment given for field 'Age' of type 'Test.Person'"
|]

[<Test>]
[<Fact>]
let ``Missing Comma In Ctor``() =
CompilerAssert.TypeCheckWithErrors
"""
Expand All @@ -48,13 +46,13 @@ let p =
Age = 18)
"""
[|
FSharpErrorSeverity.Error, 39, (7, 12, 7, 16), "The value or constructor 'Name' is not defined. Maybe you want one of the following:\r\n nan"
FSharpErrorSeverity.Error, 39, (7, 12, 7, 16), "The value or constructor 'Name' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " nan"
FSharpErrorSeverity.Warning, 20, (7, 12, 7, 25), "The result of this equality expression has type 'bool' and is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'."
FSharpErrorSeverity.Error, 39, (8, 12, 8, 15), "The value or constructor 'Age' is not defined."
FSharpErrorSeverity.Error, 501, (7, 5, 8, 21), "The object constructor 'Person' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> Person'. If some of the arguments are meant to assign values to properties, consider separating those arguments with a comma (',')."
|]

[<Test>]
[<Fact>]
let ``Missing Ctor Value``() =
CompilerAssert.TypeCheckSingleError
"""
Expand All @@ -71,7 +69,7 @@ let p =
(7, 5, 8, 21)
"The member or object constructor 'Person' requires 1 argument(s). The required signature is 'new : x:int -> Person'."

[<Test>]
[<Fact>]
let ``Extra Argument In Ctor``() =
CompilerAssert.TypeCheckSingleError
"""
Expand All @@ -87,7 +85,7 @@ let p =
(7, 5, 7, 14)
"The object constructor 'Person' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> Person'."

[<Test>]
[<Fact>]
let ``Extra Argument In Ctor2``() =
CompilerAssert.TypeCheckSingleError
"""
Expand All @@ -105,7 +103,7 @@ let p =
(9, 5, 9, 16)
"The object constructor 'Person' takes 0 argument(s) but is here given 1. The required signature is 'new : unit -> Person'."

[<Test>]
[<Fact>]
let ``Valid Comma In Rec Ctor``() =
CompilerAssert.Pass
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests
namespace FSharp.Compiler.ErrorMessages.ComponentTests

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

[<TestFixture>]
module ``Don't Suggest`` =

[<Test>]
[<Fact>]
let ``Dont Suggest Completely Wrong Stuff``() =
CompilerAssert.TypeCheckSingleError
"""
Expand All @@ -18,9 +17,9 @@ let _ = Path.GetFullPath "images"
FSharpErrorSeverity.Error
39
(2, 9, 2, 13)
"The value, namespace, type or module 'Path' is not defined. Maybe you want one of the following:\r\n Math"
("The value, namespace, type or module 'Path' is not defined. Maybe you want one of the following:" + System.Environment.NewLine + " Math")

[<Test>]
[<Fact>]
let ``Dont Suggest When Things Are Open``() =
CompilerAssert.ParseWithErrors
"""
Expand All @@ -37,7 +36,7 @@ let x = N.
FSharpErrorSeverity.Error, 222, (2, 1, 3, 1), "Files in libraries or multiple-file applications must begin with a namespace or module declaration. When using a module declaration at the start of a file the '=' sign is not allowed. If this is a top-level module, consider removing the = to resolve this error."
|]

[<Test>]
[<Fact>]
let ``Dont Suggest Intentionally Unused Variables``() =
CompilerAssert.TypeCheckSingleError
"""
Expand Down
Loading