-
Notifications
You must be signed in to change notification settings - Fork 831
More test for error recovery #18669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
More test for error recovery #18669
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
1799aaf
make attribute targets mismatches a warning and not an error.
edgarfgp 55507e9
release notes
edgarfgp 1738018
update tests
edgarfgp 65f5bb6
Merge branch 'main' into fix-attr-targets
edgarfgp 0c97b9d
Merge branch 'main' into fix-attr-targets
edgarfgp 6f2b706
update baselines
edgarfgp e8f1bb0
Merge branch 'main' into fix-attr-targets
edgarfgp 75d8f5e
Update baselines
edgarfgp 4f2e97e
Merge branch 'fix-attr-targets' of github.com:edgarfgp/fsharp into fi…
edgarfgp 63be5d5
Merge branch 'main' into fix-attr-targets
edgarfgp 4248f2a
Move attribute form logic to an AP
edgarfgp cc96217
Merge branch 'main' into fix-attr-targets
edgarfgp e270b88
Merge branch 'main' into fix-attr-targets
edgarfgp e0cc65a
Merge branch 'main' into fix-attr-targets
edgarfgp 1e29d58
Merge branch 'main' into fix-attr-targets
edgarfgp 1470bf9
Merge branch 'main' into fix-attr-targets
edgarfgp 8988215
Merge branch 'main' into fix-attr-targets
edgarfgp 74712e8
Merge branch 'main' into fix-attr-targets
edgarfgp 967c4a9
Merge branch 'main' of github.com:edgarfgp/fsharp
edgarfgp a30cef4
Merge branch 'dotnet:main' into main
edgarfgp 5fa0480
Merge branch 'dotnet:main' into main
edgarfgp 15e3d34
Merge branch 'dotnet:main' into main
edgarfgp b7ffcf8
Merge branch 'dotnet:main' into main
edgarfgp fbb5679
Add error recovery tests
edgarfgp 623a70c
Simplify testsL names and content
edgarfgp 3b55c65
Merge branch 'main' into more-test-for-error-recovery
edgarfgp 36ed82e
Merge branch 'main' into more-test-for-error-recovery
edgarfgp b0dfbe4
Merge branch 'main' into more-test-for-error-recovery
edgarfgp 6b29390
Merge branch 'main' into more-test-for-error-recovery
edgarfgp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
197 changes: 197 additions & 0 deletions
197
tests/FSharp.Compiler.ComponentTests/ErrorMessages/AbbreviationTests.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
|
||
| module ErrorMessages.AbbreviationTests | ||
|
|
||
| open Xunit | ||
| open FSharp.Test.Compiler | ||
|
|
||
| [<Fact>] | ||
| let ``Type abbreviations with members should report all member errors`` () = | ||
| Fsx """ | ||
| type StringAlias = string | ||
|
|
||
| type StringAlias with | ||
| member x.Length = x.Length | ||
| member x.ToUpper() = x.ToUpper() | ||
| static member Parse(s) = s | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 964, Line 4, Col 6, Line 4, Col 17, "Type abbreviations cannot have augmentations") | ||
| (Error 895, Line 5, Col 5, Line 5, Col 31, "Type abbreviations cannot have members") | ||
| (Error 895, Line 6, Col 5, Line 6, Col 37, "Type abbreviations cannot have members") | ||
| (Error 895, Line 7, Col 5, Line 7, Col 31, "Type abbreviations cannot have members") | ||
edgarfgp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ] | ||
|
|
||
| [<Fact>] | ||
| let ``Type abbreviations with interface declarations should report all errors`` () = | ||
| Fsx """ | ||
| type IntAlias = int | ||
|
|
||
| type IntAlias with | ||
| interface System.IComparable with | ||
| member x.CompareTo(obj) = 0 | ||
| interface System.IFormattable with | ||
| member x.ToString(format, provider) = "" | ||
| member x.Value = x | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 964, Line 4, Col 6, Line 4, Col 14, "Type abbreviations cannot have augmentations") | ||
| (Error 906, Line 5, Col 15, Line 5, Col 33, "Type abbreviations cannot have interface declarations") | ||
| (Error 909, Line 5, Col 15, Line 5, Col 33, "All implemented interfaces should be declared on the initial declaration of the type") | ||
| ] | ||
|
|
||
| [<Fact>] | ||
| let ``Type abbreviations with mixed members and interfaces should report all errors`` () = | ||
| Fsx """ | ||
| type FloatAlias = float | ||
|
|
||
| type FloatAlias with | ||
| member x.IsNaN = System.Double.IsNaN(x) | ||
| interface System.IConvertible | ||
| static member Zero = 0.0 | ||
| member x.Sqrt() = sqrt x | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 964, Line 4, Col 6, Line 4, Col 16, "Type abbreviations cannot have augmentations") | ||
| (Error 906, Line 6, Col 15, Line 6, Col 34, "Type abbreviations cannot have interface declarations") | ||
| (Error 909, Line 6, Col 15, Line 6, Col 34, "All implemented interfaces should be declared on the initial declaration of the type") | ||
| ] | ||
|
|
||
| [<Fact>] | ||
| let ``Multiple type abbreviations with errors should all be reported`` () = | ||
| Fsx """ | ||
| type ListAlias = int list | ||
| type ArrayAlias = string[] | ||
| type OptionAlias = int option | ||
|
|
||
| type ListAlias with | ||
| member x.Head = x.Head | ||
| member x.Tail = x.Tail | ||
|
|
||
| type ArrayAlias with | ||
| member x.Length = x.Length | ||
| interface System.Collections.IEnumerable with | ||
| member x.GetEnumerator() = null | ||
|
|
||
| type OptionAlias with | ||
| member x.IsSome = x.IsSome | ||
| member x.IsNone = x.IsNone | ||
edgarfgp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static member None = None | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 964, Line 6, Col 6, Line 6, Col 15, "Type abbreviations cannot have augmentations") | ||
| (Error 895, Line 7, Col 5, Line 7, Col 27, "Type abbreviations cannot have members") | ||
| (Error 895, Line 8, Col 5, Line 8, Col 27, "Type abbreviations cannot have members") | ||
| (Error 964, Line 10, Col 6, Line 10, Col 16, "Type abbreviations cannot have augmentations") | ||
| (Error 906, Line 12, Col 15, Line 12, Col 45, "Type abbreviations cannot have interface declarations") | ||
| (Error 909, Line 12, Col 15, Line 12, Col 45, "All implemented interfaces should be declared on the initial declaration of the type") | ||
| (Error 964, Line 15, Col 6, Line 15, Col 17, "Type abbreviations cannot have augmentations") | ||
| (Error 895, Line 16, Col 5, Line 16, Col 31, "Type abbreviations cannot have members") | ||
| (Error 895, Line 17, Col 5, Line 17, Col 31, "Type abbreviations cannot have members") | ||
| (Error 895, Line 18, Col 5, Line 18, Col 30, "Type abbreviations cannot have members") | ||
| (Error 1198, Line 18, Col 19, Line 18, Col 23, "The generic member 'None' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints.") | ||
|
|
||
| ] | ||
|
|
||
| [<Fact>] | ||
| let ``Nested type abbreviations with augmentations should all report errors`` () = | ||
| Fsx """ | ||
| namespace Test | ||
|
|
||
| type Alias1 = int | ||
|
|
||
| module Nested = | ||
| type Alias2 = string | ||
|
|
||
| type Alias1 with | ||
| member x.Value = x // Error | ||
|
|
||
| type Alias2 with | ||
| member x.Length = x.Length // Error | ||
| interface System.IComparable with // Error | ||
| member x.CompareTo(obj) = 0 | ||
|
|
||
| open Nested | ||
|
|
||
| type Alias2 with | ||
| member x.ToUpper() = x.ToUpper() // Error | ||
| static member Empty = "" // Error | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 964, Line 9, Col 10, Line 9, Col 16, "Type abbreviations cannot have augmentations"); | ||
| (Error 895, Line 10, Col 9, Line 10, Col 27, "Type abbreviations cannot have members"); | ||
| (Error 964, Line 12, Col 10, Line 12, Col 16, "Type abbreviations cannot have augmentations"); | ||
| (Error 906, Line 14, Col 19, Line 14, Col 37, "Type abbreviations cannot have interface declarations"); | ||
| (Error 909, Line 14, Col 19, Line 14, Col 37, "All implemented interfaces should be declared on the initial declaration of the type"); | ||
| (Error 964, Line 19, Col 6, Line 19, Col 12, "Type abbreviations cannot have augmentations"); | ||
| (Error 895, Line 20, Col 5, Line 20, Col 37, "Type abbreviations cannot have members"); | ||
| (Error 644, Line 20, Col 14, Line 20, Col 21, "Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined. Consider using a module to hold declarations of extension members."); | ||
| (Error 895, Line 21, Col 5, Line 21, Col 29, "Type abbreviations cannot have members"); | ||
| (Error 644, Line 21, Col 19, Line 21, Col 24, "Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined. Consider using a module to hold declarations of extension members.") | ||
| ] | ||
|
|
||
| [<Fact>] | ||
| let ``Generic type abbreviations with augmentations should report all errors`` () = | ||
| Fsx """ | ||
| type Result<'T> = Result<'T, string> | ||
| type MyList<'a> = 'a list | ||
|
|
||
| type Result<'T> with | ||
| member x.IsOk = match x with Ok _ -> true | Error _ -> false | ||
| member x.IsError = not x.IsOk | ||
| static member Ok(value) = Ok value | ||
|
|
||
| type MyList<'a> with | ||
| member x.Head = List.head x | ||
| member x.Tail = List.tail x | ||
| interface seq<'a> with | ||
| member x.GetEnumerator() = (x :> seq<'a>).GetEnumerator() | ||
| interface System.Collections.IEnumerable with | ||
| member x.GetEnumerator() = (x :> System.Collections.IEnumerable).GetEnumerator() | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 964, Line 5, Col 6, Line 5, Col 12, "Type abbreviations cannot have augmentations"); | ||
| (Error 895, Line 6, Col 5, Line 6, Col 65, "Type abbreviations cannot have members"); | ||
| (Error 895, Line 7, Col 5, Line 7, Col 34, "Type abbreviations cannot have members"); | ||
| (Error 895, Line 8, Col 5, Line 8, Col 39, "Type abbreviations cannot have members"); | ||
| (Error 1198, Line 8, Col 19, Line 8, Col 21, "The generic member 'Ok' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints."); | ||
| (Error 964, Line 10, Col 6, Line 10, Col 12, "Type abbreviations cannot have augmentations"); | ||
| (Error 906, Line 13, Col 15, Line 13, Col 22, "Type abbreviations cannot have interface declarations"); | ||
| (Error 909, Line 13, Col 15, Line 13, Col 22, "All implemented interfaces should be declared on the initial declaration of the type") | ||
| ] | ||
|
|
||
| [<Fact>] | ||
| let ``Type abbreviations with property getters and setters should report all errors`` () = | ||
| Fsx """ | ||
| type IntRef = int ref | ||
|
|
||
| type IntRef with | ||
| member x.Value | ||
| with get() = !x | ||
| and set(v) = x := v | ||
| member x.Increment() = x := !x + 1 | ||
| member x.Decrement() = x := !x - 1 | ||
| static member Zero = ref 0 | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 964, Line 4, Col 6, Line 4, Col 12, "Type abbreviations cannot have augmentations") | ||
| (Error 895, Line 5, Col 5, Line 6, Col 1, "Type abbreviations cannot have members") | ||
| (Error 895, Line 8, Col 5, Line 8, Col 39, "Type abbreviations cannot have members") | ||
| (Error 895, Line 9, Col 5, Line 9, Col 39, "Type abbreviations cannot have members") | ||
| (Error 895, Line 10, Col 5, Line 10, Col 31, "Type abbreviations cannot have members") | ||
| (Error 1198, Line 10, Col 19, Line 10, Col 23, "The generic member 'Zero' has been used at a non-uniform instantiation prior to this program point. Consider reordering the members so this member occurs first. Alternatively, specify the full type of the member explicitly, including argument types, return type and any additional generic parameters and constraints.") | ||
| ] | ||
67 changes: 67 additions & 0 deletions
67
tests/FSharp.Compiler.ComponentTests/ErrorMessages/NamespaceTests.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
| module ErrorMessages.NamespaceTests | ||
|
|
||
| open Xunit | ||
| open FSharp.Test.Compiler | ||
|
|
||
| [<Fact>] | ||
| let ``Namespace cannot contain value bindings - multiple let bindings`` () = | ||
| Fsx """ | ||
| namespace TestNamespace | ||
|
|
||
| let x = 1 | ||
| let y = 2 | ||
| let z = 3 | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 201, Line 4, Col 5, Line 4, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| (Error 201, Line 5, Col 5, Line 5, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| (Error 201, Line 6, Col 5, Line 6, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| ] | ||
|
|
||
| [<Fact>] | ||
| let ``Namespace cannot contain function bindings`` () = | ||
| Fsx """ | ||
| namespace TestNamespace | ||
|
|
||
| let add x y = x + y | ||
| let multiply x y = x * y | ||
| let divide x y = x / y | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 201, Line 4, Col 5, Line 4, Col 12, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| (Error 201, Line 5, Col 5, Line 5, Col 17, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| (Error 201, Line 6, Col 5, Line 6, Col 15, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| ] | ||
|
|
||
| [<Fact>] | ||
| let ``Multiple namespaces with value bindings should all report errors`` () = | ||
| Fsx """ | ||
| namespace Namespace1 | ||
|
|
||
| let x = 1 | ||
|
|
||
| namespace Namespace2 | ||
|
|
||
| let y = 2 | ||
| do printfn "test" | ||
|
|
||
| namespace Namespace3 | ||
|
|
||
| let z = 3 | ||
| let w = 4 | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withDiagnostics [ | ||
| (Error 201, Line 4, Col 5, Line 4, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| (Error 201, Line 8, Col 5, Line 8, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| (Error 201, Line 9, Col 1, Line 9, Col 18, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| (Error 201, Line 13, Col 5, Line 13, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| (Error 201, Line 14, Col 5, Line 14, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.") | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.