Skip to content

Commit

Permalink
Move existing Compiler.ComponentTests to a new Compiler.fs framework (d…
Browse files Browse the repository at this point in the history
…otnet#9839)

* Move existing Compiler.ComponentTests to a new Compiler.fs framework; Add 'parse' function

* Changed some wording in error messages
  • Loading branch information
vzarytovskii authored and abelbraaksma committed Aug 9, 2020
1 parent 29047e9 commit d2b545e
Show file tree
Hide file tree
Showing 25 changed files with 630 additions and 720 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.ConstraintSolver.ComponentTests
namespace FSharp.Compiler.ComponentTests.ConstraintSolver

open Xunit
open FSharp.Test.Utilities.Compiler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.ConstraintSolver.ComponentTests
namespace FSharp.Compiler.ComponentTests.ConstraintSolver

open Xunit
open FSharp.Test.Utilities.Compiler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,74 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

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

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

module ``Access Of Type Abbreviation`` =

let warning44Message = "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 trying to export``() =
CompilerAssert.TypeCheckSingleError
"""
FSharp """
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.")
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Warning 44, Line 4, Col 8, Line 4, Col 16, warning44Message)

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

[<Fact>]
let ``Internal type produces warning when trying to export``() =
CompilerAssert.TypeCheckSingleError
"""
FSharp """
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.")
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Warning 44, Line 4, Col 8, Line 4, Col 16, warning44Message)

[<Fact>]
let ``Private type produces warning when abbrev is internal``() =
CompilerAssert.TypeCheckSingleError
"""
FSharp """
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.")
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Warning 44, Line 4, Col 17, Line 4, Col 25, warning44Message)

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

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

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

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

open FSharp.Test.Utilities.Compiler

module ``Errors assigning to mutable objects`` =

[<Fact>]
let ``Assign to immutable error``() =
CompilerAssert.TypeCheckSingleError
"""
FSharp """
let x = 10
x <- 20
"""
FSharpErrorSeverity.Error
27
(3, 1, 3, 8)
"This value is not mutable. Consider using the mutable keyword, e.g. 'let mutable x = expression'."
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Error 27, Line 3, Col 1, Line 3, Col 8,
"This value is not mutable. Consider using the mutable keyword, e.g. 'let mutable x = expression'.")
110 changes: 53 additions & 57 deletions tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs
Original file line number Diff line number Diff line change
@@ -1,83 +1,78 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

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

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

module ``Classes`` =

[<Fact>]
let ``Tuple In Abstract Method``() =
CompilerAssert.TypeCheckWithErrors
"""
FSharp """
type IInterface =
abstract Function : (int32 * int32) -> unit
let x =
{ new IInterface with
member this.Function (i, j) = ()
}
"""
[|
FSharpErrorSeverity.Error, 768, (7, 16, 7, 36), "The member 'Function' does not accept the correct number of arguments. 1 argument(s) are expected, but 2 were given. The required signature is 'member IInterface.Function : (int32 * int32) -> unit'.\nA tuple type is required for one or more arguments. Consider wrapping the given arguments in additional parentheses or review the definition of the interface."
FSharpErrorSeverity.Error, 17, (7, 21, 7, 29), "The member 'Function : 'a * 'b -> unit' does not have the correct type to override the corresponding abstract method. The required signature is 'Function : (int32 * int32) -> unit'."
FSharpErrorSeverity.Error, 783, (6, 9, 6, 19), "At least one override did not correctly implement its corresponding abstract member"
|]
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 768, Line 7, Col 16, Line 7, Col 36, "The member 'Function' does not accept the correct number of arguments. 1 argument(s) are expected, but 2 were given. The required signature is 'member IInterface.Function : (int32 * int32) -> unit'.\nA tuple type is required for one or more arguments. Consider wrapping the given arguments in additional parentheses or review the definition of the interface.")
(Error 17, Line 7, Col 21, Line 7, Col 29, "The member 'Function : 'a * 'b -> unit' does not have the correct type to override the corresponding abstract method. The required signature is 'Function : (int32 * int32) -> unit'.")
(Error 783, Line 6, Col 9, Line 6, Col 19, "At least one override did not correctly implement its corresponding abstract member")]

[<Fact>]
let ``Wrong Arity``() =
CompilerAssert.TypeCheckSingleError
"""
FSharp """
type MyType() =
static member MyMember(arg1, arg2:int ) = ()
static member MyMember(arg1, arg2:byte) = ()
MyType.MyMember("", 0, 0)
"""
FSharpErrorSeverity.Error
503
(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."
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Error 503, Line 7, Col 1, Line 7, Col 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.")

[<Fact>]
let ``Method Is Not Static``() =
CompilerAssert.TypeCheckSingleError
"""
FSharp """
type Class1() =
member this.X() = "F#"
let x = Class1.X()
"""
FSharpErrorSeverity.Error
3214
(5, 9, 5, 17)
"Method or object constructor 'X' is not static"
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Error 3214, Line 5, Col 9, Line 5, Col 17, "Method or object constructor 'X' is not static")

[<Fact>]
let ``Matching Method With Same Name Is Not Abstract``() =
CompilerAssert.TypeCheckWithErrors
"""
FSharp """
type Foo(x : int) =
member v.MyX() = x
let foo =
{ new Foo(3)
with
member v.MyX() = 4 }
"""
[|
FSharpErrorSeverity.Error, 767, (8, 16, 8, 23), "The type Foo contains the member 'MyX' but it is not a virtual or abstract method that is available to override or implement."
FSharpErrorSeverity.Error, 17, (8, 18, 8, 21), "The member 'MyX : unit -> int' does not have the correct type to override any given virtual method"
FSharpErrorSeverity.Error, 783, (6, 11, 6, 14), "At least one override did not correctly implement its corresponding abstract member"
|]
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 767, Line 8, Col 16, Line 8, Col 23, "The type Foo contains the member 'MyX' but it is not a virtual or abstract method that is available to override or implement.")
(Error 17, Line 8, Col 18, Line 8, Col 21, "The member 'MyX : unit -> int' does not have the correct type to override any given virtual method")
(Error 783, Line 6, Col 11, Line 6, Col 14, "At least one override did not correctly implement its corresponding abstract member")]

[<Fact>]
let ``No Matching Abstract Method With Same Name``() =
CompilerAssert.TypeCheckWithErrors
"""
FSharp """
type IInterface =
abstract MyFunction : int32 * int32 -> unit
abstract SomeOtherFunction : int32 * int32 -> unit
Expand All @@ -86,42 +81,43 @@ let x =
{ new IInterface with
member this.Function (i, j) = ()
}
"""
[|
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: " + 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"
|]
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 767, Line 8, Col 14, Line 8, Col 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")
(Error 17, Line 8, Col 19, Line 8, Col 27, "The member 'Function : 'a * 'b -> unit' does not have the correct type to override any given virtual method")
(Error 366, Line 7, Col 3, Line 9, Col 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 ...'.")
(Error 783, Line 7, Col 9, Line 7, Col 19, "At least one override did not correctly implement its corresponding abstract member")]

[<Fact>]
let ``Member Has Multiple Possible Dispatch Slots``() =
CompilerAssert.TypeCheckWithErrors
"""
FSharp """
type IOverload =
abstract member Bar : int -> int
abstract member Bar : double -> int
type Overload =
interface IOverload with
override __.Bar _ = 1
"""
[|
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."
|]
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 366, Line 7, Col 15, Line 7, Col 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 ...'.")
(Error 3213, Line 8, Col 21, Line 8, Col 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.")]

[<Fact>]
let ``Do Cannot Have Visibility Declarations``() =
CompilerAssert.ParseWithErrors
"""
FSharp """
type X() =
do ()
private do ()
static member Y() = 1
"""
[|
FSharpErrorSeverity.Error, 531, (4, 5, 4, 12), "Accessibility modifiers should come immediately prior to the identifier naming a construct"
FSharpErrorSeverity.Error, 512, (4, 13, 4, 18), "Accessibility modifiers are not permitted on 'do' bindings, but 'Private' was given."
FSharpErrorSeverity.Error, 222, (2, 1, 3, 1), "Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'. Only the last source file of an application may omit such a declaration."
|]
"""
|> parse
|> shouldFail
|> withDiagnostics [
(Error 531, Line 4, Col 5, Line 4, Col 12, "Accessibility modifiers should come immediately prior to the identifier naming a construct")
(Error 512, Line 4, Col 13, Line 4, Col 18, "Accessibility modifiers are not permitted on 'do' bindings, but 'Private' was given.")
(Error 222, Line 2, Col 1, Line 3, Col 1, "Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'. Only the last source file of an application may omit such a declaration.")]
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

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

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

module ``Confusing Type Name`` =

Expand Down
Loading

0 comments on commit d2b545e

Please sign in to comment.