You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2
+
3
+
moduleErrorMessages.AbbreviationTests
4
+
5
+
openXunit
6
+
openFSharp.Test.Compiler
7
+
8
+
[<Fact>]
9
+
let``Members 01`` ()=
10
+
Fsx """
11
+
type StringAlias = string
12
+
13
+
type StringAlias with
14
+
member x.Length = x.Length
15
+
"""
16
+
|> typecheck
17
+
|> shouldFail
18
+
|> withDiagnostics [
19
+
(Error 964, Line 4, Col 6, Line 4, Col 17,"Type abbreviations cannot have augmentations")
20
+
(Error 895, Line 5, Col 5, Line 5, Col 31,"Type abbreviations cannot have members")
21
+
]
22
+
23
+
[<Fact>]
24
+
let``Members 02 -Interface impl`` ()=
25
+
Fsx """
26
+
type IntAlias = int
27
+
28
+
type IntAlias with
29
+
interface System.IComparable with
30
+
member x.CompareTo(obj) = 0
31
+
"""
32
+
|> typecheck
33
+
|> shouldFail
34
+
|> withDiagnostics [
35
+
(Error 964, Line 4, Col 6, Line 4, Col 14,"Type abbreviations cannot have augmentations")
36
+
(Error 906, Line 5, Col 15, Line 5, Col 33,"Type abbreviations cannot have interface declarations")
37
+
(Error 909, Line 5, Col 15, Line 5, Col 33,"All implemented interfaces should be declared on the initial declaration of the type")
38
+
]
39
+
40
+
[<Fact>]
41
+
let``Members 03 -Members and interface`` ()=
42
+
Fsx """
43
+
type FloatAlias = float
44
+
45
+
type FloatAlias with
46
+
member x.IsNaN = System.Double.IsNaN(x)
47
+
interface System.IConvertible
48
+
"""
49
+
|> typecheck
50
+
|> shouldFail
51
+
|> withDiagnostics [
52
+
(Error 964, Line 4, Col 6, Line 4, Col 16,"Type abbreviations cannot have augmentations")
53
+
(Error 906, Line 6, Col 15, Line 6, Col 34,"Type abbreviations cannot have interface declarations")
54
+
(Error 909, Line 6, Col 15, Line 6, Col 34,"All implemented interfaces should be declared on the initial declaration of the type")
55
+
]
56
+
57
+
[<Fact>]
58
+
let``Multiple types 01`` ()=
59
+
Fsx """
60
+
type ListAlias = int list
61
+
type ArrayAlias = string[]
62
+
63
+
type ListAlias with
64
+
member x.Head = x.Head
65
+
66
+
type ArrayAlias with
67
+
member x.Length = x.Length
68
+
"""
69
+
|> typecheck
70
+
|> shouldFail
71
+
|> withDiagnostics [
72
+
(Error 964, Line 5, Col 6, Line 5, Col 15,"Type abbreviations cannot have augmentations")
73
+
(Error 895, Line 6, Col 5, Line 6, Col 27,"Type abbreviations cannot have members")
74
+
(Error 964, Line 8, Col 6, Line 8, Col 16,"Type abbreviations cannot have augmentations")
75
+
(Error 895, Line 9, Col 5, Line 9, Col 31,"Type abbreviations cannot have members")
76
+
]
77
+
78
+
[<Fact>]
79
+
let``Multiple types 02 -With interface`` ()=
80
+
Fsx """
81
+
type ArrayAlias = string[]
82
+
83
+
type ArrayAlias with
84
+
interface System.Collections.IEnumerable with
85
+
member x.GetEnumerator() = null
86
+
"""
87
+
|> typecheck
88
+
|> shouldFail
89
+
|> withDiagnostics [
90
+
(Error 964, Line 4, Col 6, Line 4, Col 16,"Type abbreviations cannot have augmentations")
91
+
(Error 906, Line 5, Col 15, Line 5, Col 45,"Type abbreviations cannot have interface declarations")
92
+
(Error 909, Line 5, Col 15, Line 5, Col 45,"All implemented interfaces should be declared on the initial declaration of the type")
93
+
]
94
+
[<Fact>]
95
+
let``Nested 01`` ()=
96
+
Fsx """
97
+
namespace Test
98
+
99
+
type Alias1 = int
100
+
101
+
module Nested =
102
+
type Alias2 = string
103
+
104
+
type Alias1 with
105
+
member x.Value = x
106
+
"""
107
+
|> typecheck
108
+
|> shouldFail
109
+
|> withDiagnostics [
110
+
(Error 964, Line 9, Col 10, Line 9, Col 16,"Type abbreviations cannot have augmentations");
111
+
(Error 895, Line 10, Col 9, Line 10, Col 27,"Type abbreviations cannot have members");
112
+
]
113
+
114
+
[<Fact>]
115
+
let``Nested 02 -Different namespace`` ()=
116
+
Fsx """
117
+
namespace Test
118
+
119
+
module Nested =
120
+
type Alias2 = string
121
+
122
+
type Alias2 with
123
+
interface System.IComparable with
124
+
member x.CompareTo(obj) = 0
125
+
126
+
open Nested
127
+
128
+
type Alias2 with
129
+
member x.ToUpper() = x.ToUpper()
130
+
"""
131
+
|> typecheck
132
+
|> shouldFail
133
+
|> withDiagnostics [
134
+
(Error 964, Line 7, Col 10, Line 7, Col 16,"Type abbreviations cannot have augmentations");
135
+
(Error 906, Line 8, Col 19, Line 8, Col 37,"Type abbreviations cannot have interface declarations");
136
+
(Error 909, Line 8, Col 19, Line 8, Col 37,"All implemented interfaces should be declared on the initial declaration of the type");
137
+
(Error 964, Line 13, Col 6, Line 13, Col 12,"Type abbreviations cannot have augmentations");
138
+
(Error 895, Line 14, Col 5, Line 14, Col 37,"Type abbreviations cannot have members");
139
+
(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.");
140
+
]
141
+
142
+
[<Fact>]
143
+
let``Generic 01`` ()=
144
+
Fsx """
145
+
type Result<'T> = Result<'T, string>
146
+
147
+
type Result<'T> with
148
+
member x.IsOk = match x with Ok _ -> true | Error _ -> false
149
+
"""
150
+
|> typecheck
151
+
|> shouldFail
152
+
|> withDiagnostics [
153
+
(Error 964, Line 4, Col 6, Line 4, Col 12,"Type abbreviations cannot have augmentations");
154
+
(Error 895, Line 5, Col 5, Line 5, Col 65,"Type abbreviations cannot have members");
155
+
]
156
+
157
+
[<Fact>]
158
+
let``Generic 02 -Interface`` ()=
159
+
Fsx """
160
+
type MyList<'a> = 'a list
161
+
162
+
type MyList<'a> with
163
+
interface seq<'a> with
164
+
member x.GetEnumerator() = (x :> seq<'a>).GetEnumerator()
165
+
"""
166
+
|> typecheck
167
+
|> shouldFail
168
+
|> withDiagnostics [
169
+
(Error 964, Line 4, Col 6, Line 4, Col 12,"Type abbreviations cannot have augmentations");
170
+
(Error 906, Line 5, Col 15, Line 5, Col 22,"Type abbreviations cannot have interface declarations");
171
+
(Error 909, Line 5, Col 15, Line 5, Col 22,"All implemented interfaces should be declared on the initial declaration of the type")
172
+
]
173
+
174
+
[<Fact>]
175
+
let``Property getters and setters`` ()=
176
+
Fsx """
177
+
type IntRef = int ref
178
+
179
+
type IntRef with
180
+
member x.Value
181
+
with get() = !x
182
+
and set(v) = x := v
183
+
"""
184
+
|> typecheck
185
+
|> shouldFail
186
+
|> withDiagnostics [
187
+
(Error 964, Line 4, Col 6, Line 4, Col 12,"Type abbreviations cannot have augmentations")
188
+
(Error 895, Line 5, Col 5, Line 6, Col 1,"Type abbreviations cannot have members")
0 commit comments