Skip to content
Merged
Show file tree
Hide file tree
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 Apr 23, 2025
55507e9
release notes
edgarfgp Apr 23, 2025
1738018
update tests
edgarfgp Apr 23, 2025
65f5bb6
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 24, 2025
0c97b9d
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 27, 2025
6f2b706
update baselines
edgarfgp Apr 29, 2025
e8f1bb0
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 29, 2025
75d8f5e
Update baselines
edgarfgp Apr 29, 2025
4f2e97e
Merge branch 'fix-attr-targets' of github.com:edgarfgp/fsharp into fi…
edgarfgp Apr 29, 2025
63be5d5
Merge branch 'main' into fix-attr-targets
edgarfgp Apr 30, 2025
4248f2a
Move attribute form logic to an AP
edgarfgp Apr 30, 2025
cc96217
Merge branch 'main' into fix-attr-targets
edgarfgp May 1, 2025
e270b88
Merge branch 'main' into fix-attr-targets
edgarfgp May 1, 2025
e0cc65a
Merge branch 'main' into fix-attr-targets
edgarfgp May 2, 2025
1e29d58
Merge branch 'main' into fix-attr-targets
edgarfgp May 5, 2025
1470bf9
Merge branch 'main' into fix-attr-targets
edgarfgp May 6, 2025
8988215
Merge branch 'main' into fix-attr-targets
edgarfgp May 7, 2025
74712e8
Merge branch 'main' into fix-attr-targets
edgarfgp May 12, 2025
967c4a9
Merge branch 'main' of github.com:edgarfgp/fsharp
edgarfgp May 13, 2025
a30cef4
Merge branch 'dotnet:main' into main
edgarfgp May 22, 2025
5fa0480
Merge branch 'dotnet:main' into main
edgarfgp May 24, 2025
15e3d34
Merge branch 'dotnet:main' into main
edgarfgp May 29, 2025
b7ffcf8
Merge branch 'dotnet:main' into main
edgarfgp Jun 6, 2025
fbb5679
Add error recovery tests
edgarfgp Jun 6, 2025
623a70c
Simplify testsL names and content
edgarfgp Jun 9, 2025
3b55c65
Merge branch 'main' into more-test-for-error-recovery
edgarfgp Jun 9, 2025
36ed82e
Merge branch 'main' into more-test-for-error-recovery
edgarfgp Jun 10, 2025
b0dfbe4
Merge branch 'main' into more-test-for-error-recovery
edgarfgp Jun 10, 2025
6b29390
Merge branch 'main' into more-test-for-error-recovery
edgarfgp Jun 10, 2025
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
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")
]

[<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
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.")
]
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.")
]
Loading
Loading