Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cyclic check for struct tuple and tests #10645

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion src/fsharp/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4221,7 +4221,12 @@ module EstablishTypeDefinitionCores =
and accStructFieldType structTycon structTyInst fspec fieldTy (doneTypes, acc) =
let fieldTy = stripTyparEqns fieldTy
match fieldTy with
| TType_app (tcref2, tinst2) when tcref2.IsStructOrEnumTycon ->
| TType_tuple (_isStruct , tinst2) when isStructTupleTy cenv.g fieldTy ->
// The field is a struct tuple. Check each element of the tuple.
// This case was added to resolve issues/3916
((doneTypes, acc), tinst2)
||> List.fold (fun acc' x -> accStructFieldType structTycon structTyInst fspec x acc')
| TType_app (tcref2 , tinst2) when tcref2.IsStructOrEnumTycon ->
// The field is a struct.
// An edge (tycon, tycon2) should be recorded, unless it is the "static self-typed field" case.
let tycon2 = tcref2.Deref
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="Interop\SimpleInteropTests.fs" />
<Compile Include="Interop\VisibilityTests.fs" />
<Compile Include="Scripting\Interactive.fs" />
<Compile Include="TypeChecks\CheckDeclarationsTests.fs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.ComponentTests.CheckDeclarationsTests

open Xunit
open FSharp.Test.Utilities.Compiler
open FSharp.Test.Utilities.Xunit.Attributes

module CheckDeclarationsTests =

[<Fact>]
let ``CheckingSyntacticTypes - TcTyconDefnCore_CheckForCyclicStructsAndInheritance - Struct DU with Cyclic Tuple`` () =
FSharp """
namespace FSharpTest

[<Struct>]
type Tree =
| Empty
| Children of Tree * Tree
"""
|> compile
|> shouldFail
|> withErrorCode 954
|> ignore

[<Fact>]
let ``CheckingSyntacticTypes - TcTyconDefnCore_CheckForCyclicStructsAndInheritance - Struct DU with Cyclic Struct Tuple`` () =
FSharp """
namespace FSharpTest

[<Struct>]
type Tree =
| Empty
| Children of struct (Tree * Tree)
"""
|> compile
|> shouldFail
|> withErrorCode 954
|> ignore

[<Fact>]
let ``CheckingSyntacticTypes - TcTyconDefnCore_CheckForCyclicStructsAndInheritance - Struct DU with Cyclic Struct Tuple of int, Tree`` () =
FSharp """
namespace FSharpTest

[<Struct>]
type Tree =
| Empty
| Children of struct (int * Tree)
"""
|> compile
|> shouldFail
|> withErrorCode 954
|> ignore

[<Fact>]
let ``CheckingSyntacticTypes - TcTyconDefnCore_CheckForCyclicStructsAndInheritance - Struct DU with Cyclic Tree`` () =
FSharp """
namespace FSharpTest

[<Struct>]
type Tree =
| Empty
| Children of Tree
"""
|> compile
|> shouldFail
|> withErrorCode 954
|> ignore

[<Fact>]
let ``CheckingSyntacticTypes - TcTyconDefnCore_CheckForCyclicStructsAndInheritance - Struct DU with Non-cyclic Struct Tuple`` () =
FSharp """
namespace FSharpTest

[<Struct>]
type NotATree =
| Empty
| Children of struct (int * string)
"""
|> compile
|> shouldSucceed
|> ignore

[<Fact>]
let ``CheckingSyntacticTypes - TcTyconDefnCore_CheckForCyclicStructsAndInheritance - Non-Struct DU Tree Cyclic Tree`` () =
FSharp """
namespace FSharpTest

type Tree =
| Empty
| Children of Tree
"""
|> compile
|> shouldSucceed
|> ignore