Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Split Linux CoreCLR CI into two parallel test batches to reduce test turnaround time. ([PR #20587](https://github.com/dotnet/fsharp/pull/20587))
* Fix `NativePtr.stackalloc` used inside the `with` handler, filter or `finally` block of a `try` expression producing an assembly that throws `InvalidProgramException` at method load. Direct or mandatory-inline allocations are now reported at compile time as error FS3924; calls to non-inline allocation helpers, including handler-local helpers, remain legal and retain their method boundary during inlining and let-binding elimination. ([Issue #20295](https://github.com/dotnet/fsharp/issues/20295), [PR #20491](https://github.com/dotnet/fsharp/pull/20491))
* `FsiEvaluationSession.EvalInteraction` and `EvalInteractionNonThrowing` evaluate every `;;`-separated interaction in the text they are given, as their documentation has always said, instead of silently discarding everything after the first. ([PR #20396](https://github.com/dotnet/fsharp/pull/20396))
* Struct/reference anonymous-record mismatches now name anonymous records rather than tuples. ([Issue #6110](https://github.com/dotnet/fsharp/issues/6110), [PR #20681](https://github.com/dotnet/fsharp/pull/20681))
* Preserve constraint inference order when explicit generic arguments share a caller type parameter, avoiding spurious FS0001 errors with multiply implemented generic interfaces. ([PR #20491](https://github.com/dotnet/fsharp/pull/20491))

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ and SolveTyparsEqualTypesAux (csenv: ConstraintSolverEnv) ndeep m2 (trace: Optio

and SolveAnonInfoEqualsAnonInfo (csenv: ConstraintSolverEnv) m2 (anonInfo1: AnonRecdTypeInfo) (anonInfo2: AnonRecdTypeInfo) =
if evalTupInfoIsStruct anonInfo1.TupInfo <> evalTupInfoIsStruct anonInfo2.TupInfo then
ErrorD (ConstraintSolverError(RichText.mkText (FSComp.SR.tcTupleStructMismatch()), csenv.m,m2))
ErrorD (ConstraintSolverError(RichText.mkText (FSComp.SR.tcAnonRecdStructMismatch()), csenv.m,m2))
else
trackErrors {
if not (ccuEq anonInfo1.Assembly anonInfo2.Assembly) then
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,7 @@ tcGlobalsSystemTypeNotFound,"The system type '%s' was required but no referenced
3214,methodIsNotStatic,"Method or object constructor '%s' is not static"
3215,parsUnexpectedSymbolEqualsInsteadOfIn,"Unexpected symbol '=' in expression. Did you intend to use 'for x in y .. z do' instead?"
tcAnonRecdInvalid,"Invalid Anonymous Record type declaration."
tcAnonRecdStructMismatch,"One anonymous record type is a struct, the other is a reference type"
tcAnonRecdCcuMismatch,"Two anonymous record types are from different assemblies '%s' and '%s'"
tcAnonRecdFieldNameMismatch,"This anonymous record does not exactly match the expected shape. Add the missing fields %s and remove the extra fields %s."
tcAnonRecdSingleFieldNameSubset,"This anonymous record is missing field '%s'."
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,121 @@ open FSharp.Test.Compiler

module AnonymousRecord =

let private structnessMismatch = "One anonymous record type is a struct, the other is a reference type"

let private checkArgumentMismatch parameterType value message =
Fsx $"let consume (x: {parameterType}) = ()\nlet value = {value}\nconsume value"
|> typecheck
|> shouldFail
|> withErrorCode 1
|> withMessage message

[<Fact>]
let ``Issue 6110 - mismatch original argument`` () =
Fsx """
let test (ar: {| IntVal: int |}) = printfn "%d" ar.IntVal

test struct {| IntVal=12 |}
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Error 1, Line 4, Col 6, Line 4, Col 28, structnessMismatch)

[<Theory>]
[<InlineData("struct {| IntVal: int |}", "{| IntVal = 12 |}")>]
[<InlineData("{| A: int; B: string; C: bool |}", "struct {| C = true; A = 1; B = \"b\" |}")>]
[<InlineData("struct {| A: int; B: string; C: bool |}", "{| B = \"b\"; C = true; A = 1 |}")>]
[<InlineData("{| Inner: {| Value: int |} |}", "{| Inner = struct {| Value = 1 |} |}")>]
let ``Issue 6110 - mismatch pre-bound argument`` parameterType value =
checkArgumentMismatch parameterType value structnessMismatch

[<Theory>]
[<InlineData("let value = struct {| IntVal = 12 |}\nlet annotated: {| IntVal: int |} = value")>]
[<InlineData("let reference = {||}\nlet value = struct {||}\nlet same = reference = value")>]
[<InlineData("let reference = {||}\nlet value = struct {||}\nlet same = value = reference")>]
[<InlineData("let value = struct {| Value = 1 |}\nlet values: {| Value: int |} list = [value]")>]
[<InlineData("module Consumer =\n let consume (x: {| Value: int |}) = ()\nlet value = struct {| Value = 1 |}\nConsumer.consume value")>]
let ``Issue 6110 - mismatch unification`` source =
Fsx source
|> typecheck
|> shouldFail
|> withErrorCode 1
|> withMessage structnessMismatch

let private genericConsumerSource kind typeName payload =
$"""
let consume<'T> (x: {{| Value: 'T |}}) = ()
let value = {kind} {{| Value = {payload} |}}
consume<{typeName}> value
"""

[<Theory>]
[<InlineData("int", "1")>]
[<InlineData("string", "\"text\"")>]
let ``Issue 6110 - mismatch generic argument`` typeName payload =
Fsx (genericConsumerSource "struct" typeName payload)
|> typecheck
|> shouldFail
|> withErrorCode 1
|> withMessage structnessMismatch

[<Theory>]
[<InlineData("", "{| IntVal: int |}", "{| IntVal = 12 |}")>]
[<InlineData("struct", "{| IntVal: int |}", "{| IntVal = 12 |}")>]
[<InlineData("", "{| Inner: {| Value: int |} |}", "{| Inner = {| Value = 1 |} |}")>]
[<InlineData("struct", "{| Inner: struct {| Value: int |} |}", "{| Inner = struct {| Value = 1 |} |}")>]
[<InlineData("", "(int * int)", "(1, 2)")>]
[<InlineData("struct", "(int * int)", "(1, 2)")>]
let ``Issue 6110 - control matching kinds`` kind parameterType value =
Fsx $"let consume (x: {kind} {parameterType}) = ()\nlet value = {kind} {value}\nconsume value"
|> typecheck
|> shouldSucceed

[<Theory>]
[<InlineData("int", "1")>]
[<InlineData("string", "\"text\"")>]
let ``Issue 6110 - control matching generic argument`` typeName payload =
Fsx (genericConsumerSource "" typeName payload)
|> typecheck
|> shouldSucceed

[<Fact>]
let ``Issue 6110 - control fresh literal inference`` () =
Fsx """
let consume (x: struct {| IntVal: int |}) = ()
consume {| IntVal = 12 |}
"""
|> typecheck
|> shouldSucceed

[<Theory>]
[<InlineData("", "struct")>]
[<InlineData("struct", "")>]
let ``Issue 6110 - control explicit copy conversion`` sourceKind targetKind =
Fsx $"""
let value = {sourceKind} {{| IntVal = 1 |}}
let converted: {targetKind} {{| IntVal: int |}} = {targetKind} {{| value with IntVal = 2 |}}
"""
|> typecheck
|> shouldSucceed

[<Theory>]
[<InlineData("(int * int)", "struct (1, 2)")>]
[<InlineData("struct (int * int)", "(1, 2)")>]
let ``Issue 6110 - control tuple mismatch`` parameterType value =
checkArgumentMismatch parameterType value "One tuple type is a struct tuple, the other is a reference tuple"

[<Fact>]
let ``Issue 6110 - control field type mismatch`` () =
Fsx """
let consume (x: {| IntVal: int |}) = ()
let value = {| IntVal = "wrong" |}
consume value
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Error 1, Line 4, Col 9, Line 4, Col 14, "Type mismatch. Expecting a\n '{| IntVal: int |}' \nbut given a\n '{| IntVal: string |}' \nThe type 'int' does not match the type 'string'")

[<Fact>]
let ``Anonymous Records with duplicate labels`` () =
FSharp """
Expand Down
Loading