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
Copy file name to clipboardExpand all lines: tests/FSharp.Compiler.ComponentTests/Conformance/Expressions/ObjectExpressions/ObjectExpressions.fs
+54-5Lines changed: 54 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -65,17 +65,66 @@ type Foo() = class end
65
65
66
66
let foo = { new Foo() } // Approved suggestion to allow this https://github.com/fsharp/fslang-suggestions/issues/632
67
67
68
+
let foo1 = new Foo()
69
+
68
70
// hacky workaround
69
-
let foo = { new Foo() with member __.ToString() = base.ToString() }
71
+
let foo2 = { new Foo() with member __.ToString() = base.ToString() }
72
+
"""
73
+
|> withLangVersion80
74
+
|> typecheck
75
+
|> shouldFail
76
+
|> withDiagnostics [
77
+
(Error 738, Line 5, Col 11, Line 5, Col 24,"Invalid object expression. Objects without overrides or interfaces should use the expression form 'new Type(args)' without braces.")
78
+
(Error 759, Line 7, Col 12, Line 7, Col 21,"Instances of this type cannot be created since it has been marked abstract or not all methods have been given implementations. Consider using an object expression '{ new ... with ... }' instead.")
79
+
]
80
+
81
+
[<Fact>]
82
+
let``Error when object expression does not implement all abstract members of the abstract class`` ()=
83
+
Fsx """
84
+
[<AbstractClass>]
85
+
type B() =
86
+
abstract M : int -> float
87
+
abstract M : string -> unit
88
+
and [<AbstractClass>]
89
+
C() =
90
+
inherit B()
91
+
static let v = { new C() with
92
+
member x.M(a:int) : float = 1.0 }
93
+
default x.M(a:int) : float = 1.0
94
+
95
+
let y = { new C() with
96
+
member x.M(a:int) : float = 1.0 }
97
+
"""
98
+
|> withLangVersion80
99
+
|> typecheck
100
+
|> shouldFail
101
+
|> withDiagnostics [
102
+
(Error 365, Line 9, Col 20, Line 10, Col 60,"No implementation was given for 'abstract B.M: string -> unit'")
103
+
(Error 365, Line 13, Col 9, Line 14, Col 49,"No implementation was given for 'abstract B.M: string -> unit'")
104
+
]
105
+
106
+
[<Fact>]
107
+
let``Error when object expression does not implement all abstract members of a generic abstract class`` ()=
108
+
Fsx """
109
+
[<AbstractClass>]
110
+
type BaseHashtable<'Entry, 'Key>(initialCapacity) =
111
+
abstract member Next : entries : 'Entry array -> int
112
+
113
+
[<Struct>]
114
+
type StrongToWeakEntry<'Value when 'Value : not struct> =
(Error 759, Line 5, Col 13, Line 5, Col 22,"Instances of this type cannot be created since it has been marked abstract or not all methods have been given implementations. Consider using an object expression '{ new ... with ... }' instead.");
76
-
(Error 738, Line 5, Col 11, Line 5, Col 24,"Invalid object expression. Objects without overrides or interfaces should use the expression form 'new Type(args)' without braces.")
77
-
(Error 740, Line 5, Col 11, Line 5, Col 24,"Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'")
78
-
]
126
+
(Error 359, Line 10, Col 11, Line 13, Col 12,"More than one override implements 'Next: StrongToWeakEntry<'a> array -> int when 'a: not struct'")
127
+
]
79
128
80
129
[<Fact>]
81
130
let``Object expression can not implementing an interface when it contains a method with no types that can refer to the type for which the implementation is being used`` ()=
0 commit comments