|
4 | 4 | open FSharp.Compiler.Text
|
5 | 5 | open FSharp.Compiler.Diagnostics
|
6 | 6 | open FSharp.Compiler.Diagnostics.ExtendedData
|
7 |
| -open FSharp.Test |
8 | 7 | open FSharp.Test.Compiler
|
9 | 8 | open Xunit
|
10 | 9 |
|
@@ -144,6 +143,50 @@ if true then 1 else "a"
|
144 | 143 | Assert.Equal("int", typeMismatch.ExpectedType.Format(displayContext))
|
145 | 144 | Assert.Equal("string", typeMismatch.ActualType.Format(displayContext)))
|
146 | 145 |
|
| 146 | +[<Fact>] |
| 147 | +let ``TypeMismatchDiagnosticExtendedData 08`` () = |
| 148 | + FSharp """ |
| 149 | +type R = { Field1: int } |
| 150 | +let f (x: R) = "" + x.Field1 |
| 151 | +""" |
| 152 | + |> typecheckResults |
| 153 | + |> checkDiagnostic |
| 154 | + (1, "The type 'int' does not match the type 'string'") |
| 155 | + (fun (typeMismatch: TypeMismatchDiagnosticExtendedData) -> |
| 156 | + let displayContext = typeMismatch.DisplayContext |
| 157 | + Assert.Equal(DiagnosticContextInfo.NoContext, typeMismatch.ContextInfo) |
| 158 | + Assert.Equal("string", typeMismatch.ExpectedType.Format(displayContext)) |
| 159 | + Assert.Equal("int", typeMismatch.ActualType.Format(displayContext))) |
| 160 | + |
| 161 | +[<Fact>] |
| 162 | +let ``TypeMismatchDiagnosticExtendedData 09`` () = |
| 163 | + FSharp """ |
| 164 | +let x: string = 1 |
| 165 | +""" |
| 166 | + |> typecheckResults |
| 167 | + |> checkDiagnostic |
| 168 | + (1, "This expression was expected to have type\n 'string' \nbut here has type\n 'int' ") |
| 169 | + (fun (typeMismatch: TypeMismatchDiagnosticExtendedData) -> |
| 170 | + let displayContext = typeMismatch.DisplayContext |
| 171 | + Assert.Equal(DiagnosticContextInfo.NoContext, typeMismatch.ContextInfo) |
| 172 | + Assert.Equal("string", typeMismatch.ExpectedType.Format(displayContext)) |
| 173 | + Assert.Equal("int", typeMismatch.ActualType.Format(displayContext))) |
| 174 | + |
| 175 | +[<Fact>] |
| 176 | +let ``TypeMismatchDiagnosticExtendedData 10`` () = |
| 177 | + FSharp """ |
| 178 | +let f1 (x: outref<'T>) = 1 |
| 179 | +let f2 (x: inref<'T>) = f1 &x |
| 180 | +""" |
| 181 | + |> typecheckResults |
| 182 | + |> checkDiagnostic |
| 183 | + (1, "Type mismatch. Expecting a\n 'outref<'T>' \nbut given a\n 'inref<'T>' \nThe type 'ByRefKinds.Out' does not match the type 'ByRefKinds.In'") |
| 184 | + (fun (typeMismatch: TypeMismatchDiagnosticExtendedData) -> |
| 185 | + let displayContext = typeMismatch.DisplayContext |
| 186 | + Assert.Equal(DiagnosticContextInfo.NoContext, typeMismatch.ContextInfo) |
| 187 | + Assert.Equal("outref<'T>", typeMismatch.ExpectedType.Format(displayContext)) |
| 188 | + Assert.Equal("inref<'T>", typeMismatch.ActualType.Format(displayContext))) |
| 189 | + |
147 | 190 | [<Theory>]
|
148 | 191 | [<InlineData true>]
|
149 | 192 | [<InlineData false>]
|
|
0 commit comments