Skip to content

Commit c886ffa

Browse files
committed
undo inlining of DynObj.combine
1 parent dcf4e5e commit c886ffa

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

DynamicObj.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "DynamicObject.Immutable.Tes
5151
EndProject
5252
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E0867002-4410-4E5F-BE71-46ABBE93ED07}"
5353
EndProject
54+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpConsole", "tests\FSharpConsole\FSharpConsole.fsproj", "{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}"
55+
EndProject
5456
Global
5557
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5658
Debug|Any CPU = Debug|Any CPU
@@ -81,6 +83,10 @@ Global
8183
{0F6A539F-82D2-4BDC-8BF0-F2D261873B92}.Debug|Any CPU.Build.0 = Debug|Any CPU
8284
{0F6A539F-82D2-4BDC-8BF0-F2D261873B92}.Release|Any CPU.ActiveCfg = Release|Any CPU
8385
{0F6A539F-82D2-4BDC-8BF0-F2D261873B92}.Release|Any CPU.Build.0 = Release|Any CPU
86+
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
87+
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}.Debug|Any CPU.Build.0 = Debug|Any CPU
88+
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}.Release|Any CPU.ActiveCfg = Release|Any CPU
89+
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D}.Release|Any CPU.Build.0 = Release|Any CPU
8490
EndGlobalSection
8591
GlobalSection(SolutionProperties) = preSolution
8692
HideSolutionNode = FALSE
@@ -92,6 +98,7 @@ Global
9298
{5E7DAC28-7752-4209-B3BB-6DCE54C28AD8} = {E0867002-4410-4E5F-BE71-46ABBE93ED07}
9399
{39192F2D-164B-4905-A7D7-5C5B0FFCD2BB} = {988D804A-3A42-4E46-B233-B64F5C22524B}
94100
{0F6A539F-82D2-4BDC-8BF0-F2D261873B92} = {988D804A-3A42-4E46-B233-B64F5C22524B}
101+
{AF8AE8C7-B7C9-4CAC-9FE4-F5BCF015798D} = {988D804A-3A42-4E46-B233-B64F5C22524B}
95102
EndGlobalSection
96103
GlobalSection(ExtensibilityGlobals) = postSolution
97104
SolutionGuid = {6F5C3597-4524-4A4E-94EC-44857BD0BCEC}

src/DynamicObj/DynObj.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module DynObj =
5050
/// <param name="first"></param>
5151
/// <param name="second"></param>
5252
/// <remarks>This function mutates the first input DynamicObj</remarks>
53-
let rec combine (first:#DynamicObj) (second:#DynamicObj) =
53+
let rec combine (first:DynamicObj) (second:DynamicObj) =
5454
//printfn "Type %A" (first.GetType())
5555
/// Consider deep-copy of first
5656
for kv in (second.GetProperties true) do

tests/DynamicObject.Tests/DynObj.fs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ let tests_ofArray = ptestList "ofArray" [
4949
Expect.equal (dyn.GetPropertyValue("key2")) 2 "Value should be 2"
5050
]
5151

52+
type Inner() =
53+
inherit DynamicObj()
54+
static member init(
55+
?inner_value: string
56+
) =
57+
Inner()
58+
|> DynObj.withOptionalProperty "inner_value" inner_value
59+
60+
type Outer() =
61+
inherit DynamicObj()
62+
static member init(
63+
?A: int,
64+
?B: string,
65+
?Inner: Inner
66+
) =
67+
Outer()
68+
|> DynObj.withOptionalProperty "A" A
69+
|> DynObj.withOptionalProperty "B" B
70+
|> DynObj.withOptionalProperty "Inner" Inner
71+
5272
let tests_combine = testList "combine" [
5373

5474
testCase "Combine flat DOs" <| fun _ ->
@@ -109,6 +129,12 @@ let tests_combine = testList "combine" [
109129
)
110130

111131
Expect.equal expected combined "Combine nested DOs failed"
132+
133+
testCase "Combine nested DOs with inheriting types" <| fun _ ->
134+
let outer1 = Outer.init(A = 1, B = "first", Inner = Inner.init(inner_value = "inner_first"))
135+
let outer2 = Outer.init(A = 2, B = "second", Inner = Inner.init(inner_value = "inner_second"))
136+
let expected = Outer.init(A = 2, B = "second", Inner = Inner.init(inner_value = "inner_second"))
137+
Expect.equal (expected) (DynObj.combine outer1 outer2 |> unbox) "Combine nested DOs with inheriting types failed"
112138
]
113139

114140
let tests_tryGetTypedPropertyValue = testList "tryGetTypedPropertyValue" [
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Program.fs" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\DynamicObj\DynamicObj.fsproj" />
14+
</ItemGroup>
15+
16+
</Project>

tests/FSharpConsole/Program.fs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// For more information see https://aka.ms/fsharp-console-apps
2+
3+
open DynamicObj
4+
5+
type Inner() =
6+
inherit DynamicObj()
7+
static member init(
8+
?inner_value: string
9+
) =
10+
Inner()
11+
|> DynObj.withOptionalProperty "inner_value" inner_value
12+
13+
type Outer() =
14+
inherit DynamicObj()
15+
static member init(
16+
?A: int,
17+
?B: string,
18+
?Inner: Inner
19+
) =
20+
Outer()
21+
|> DynObj.withOptionalProperty "A" A
22+
|> DynObj.withOptionalProperty "B" B
23+
|> DynObj.withOptionalProperty "Inner" Inner
24+
25+
26+
let outer1 = Outer.init(A = 1, B = "first", Inner = Inner.init(inner_value = "inner_first"))
27+
let outer2 = Outer.init(A = 2, B = "second", Inner = Inner.init(inner_value = "inner_second"))
28+
let expected = Outer.init(A = 2, B = "second", Inner = Inner.init(inner_value = "inner_second"))
29+
30+
printfn "%A" ((DynObj.combine outer1 outer2) = expected)

0 commit comments

Comments
 (0)