Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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,189 @@
// 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 ``Members 01`` () =
Fsx """
type StringAlias = string

type StringAlias with
member x.Length = x.Length
"""
|> 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")
]

[<Fact>]
let ``Members 02 - Interface impl`` () =
Fsx """
type IntAlias = int

type IntAlias with
interface System.IComparable with
member x.CompareTo(obj) = 0
"""
|> 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 ``Members 03 - Members and interface`` () =
Fsx """
type FloatAlias = float

type FloatAlias with
member x.IsNaN = System.Double.IsNaN(x)
interface System.IConvertible
"""
|> 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 types 01`` () =
Fsx """
type ListAlias = int list
type ArrayAlias = string[]

type ListAlias with
member x.Head = x.Head

type ArrayAlias with
member x.Length = x.Length
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 964, Line 5, Col 6, Line 5, Col 15, "Type abbreviations cannot have augmentations")
(Error 895, Line 6, Col 5, Line 6, Col 27, "Type abbreviations cannot have members")
(Error 964, Line 8, Col 6, Line 8, Col 16, "Type abbreviations cannot have augmentations")
(Error 895, Line 9, Col 5, Line 9, Col 31, "Type abbreviations cannot have members")
]

[<Fact>]
let ``Multiple types 02 - With interface`` () =
Fsx """
type ArrayAlias = string[]

type ArrayAlias with
interface System.Collections.IEnumerable with
member x.GetEnumerator() = null
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 964, Line 4, Col 6, Line 4, Col 16, "Type abbreviations cannot have augmentations")
(Error 906, Line 5, Col 15, Line 5, Col 45, "Type abbreviations cannot have interface declarations")
(Error 909, Line 5, Col 15, Line 5, Col 45, "All implemented interfaces should be declared on the initial declaration of the type")
]
[<Fact>]
let ``Nested 01`` () =
Fsx """
namespace Test

type Alias1 = int

module Nested =
type Alias2 = string

type Alias1 with
member x.Value = x
"""
|> 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");
]

[<Fact>]
let ``Nested 02 - Different namespace`` () =
Fsx """
namespace Test

module Nested =
type Alias2 = string

type Alias2 with
interface System.IComparable with
member x.CompareTo(obj) = 0

open Nested

type Alias2 with
member x.ToUpper() = x.ToUpper()
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 964, Line 7, Col 10, Line 7, Col 16, "Type abbreviations cannot have augmentations");
(Error 906, Line 8, Col 19, Line 8, Col 37, "Type abbreviations cannot have interface declarations");
(Error 909, Line 8, Col 19, Line 8, Col 37, "All implemented interfaces should be declared on the initial declaration of the type");
(Error 964, Line 13, Col 6, Line 13, Col 12, "Type abbreviations cannot have augmentations");
(Error 895, Line 14, Col 5, Line 14, Col 37, "Type abbreviations cannot have members");
(Error 644, Line 14, Col 14, Line 14, 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.");
]

[<Fact>]
let ``Generic 01`` () =
Fsx """
type Result<'T> = Result<'T, string>

type Result<'T> with
member x.IsOk = match x with Ok _ -> true | Error _ -> false
"""
|> 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 5, Col 65, "Type abbreviations cannot have members");
]

[<Fact>]
let ``Generic 02 - Interface`` () =
Fsx """
type MyList<'a> = 'a list

type MyList<'a> with
interface seq<'a> with
member x.GetEnumerator() = (x :> seq<'a>).GetEnumerator()
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 964, Line 4, Col 6, Line 4, Col 12, "Type abbreviations cannot have augmentations");
(Error 906, Line 5, Col 15, Line 5, Col 22, "Type abbreviations cannot have interface declarations");
(Error 909, Line 5, Col 15, Line 5, Col 22, "All implemented interfaces should be declared on the initial declaration of the type")
]

[<Fact>]
let ``Property getters and setters`` () =
Fsx """
type IntRef = int ref

type IntRef with
member x.Value
with get() = !x
and set(v) = x := v
"""
|> 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")
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 ``Value bindings 01`` () =
Fsx """
namespace TestNamespace

let x = 1
"""
|> 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.")
]

[<Fact>]
let ``Value bindings 02 - Multiple`` () =
Fsx """
namespace TestNamespace

let x = 1
let y = 2
"""
|> 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.")
]

[<Fact>]
let ``Function bindings`` () =
Fsx """
namespace TestNamespace

let add 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.")
]

[<Fact>]
let ``Multiple namespaces`` () =
Fsx """
namespace Namespace1

let x = 1

namespace Namespace2

let y = 2

namespace Namespace3

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 8, Col 5, Line 8, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.")
(Error 201, Line 12, Col 5, Line 12, Col 6, "Namespaces cannot contain values. Consider using a module to hold your value declarations.")
]

[<Fact>]
let ``Do expressions`` () =
Fsx """
namespace TestNamespace

do printfn "test"
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 201, Line 4, Col 1, Line 4, Col 18, "Namespaces cannot contain values. Consider using a module to hold your value declarations.")
]
Loading
Loading