Skip to content

Commit 6f54944

Browse files
authored
Fix improper casts during clone (#284)
Fixes #274
1 parent a871164 commit 6f54944

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

src/Temporalio/Client/Schedules/ScheduleListOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ScheduleListOptions : ICloneable
1919
/// <returns>A shallow copy of these options and any transitive options fields.</returns>
2020
public virtual object Clone()
2121
{
22-
var copy = (WorkflowListOptions)MemberwiseClone();
22+
var copy = (ScheduleListOptions)MemberwiseClone();
2323
if (Rpc != null)
2424
{
2525
copy.Rpc = (RpcOptions)Rpc.Clone();

src/Temporalio/Client/Schedules/ScheduleOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class ScheduleOptions : ICloneable
4242
/// <returns>A shallow copy of these options and any transitive options fields.</returns>
4343
public virtual object Clone()
4444
{
45-
var copy = (WorkflowOptions)MemberwiseClone();
45+
var copy = (ScheduleOptions)MemberwiseClone();
4646
if (Rpc != null)
4747
{
4848
copy.Rpc = (RpcOptions)Rpc.Clone();

src/Temporalio/Client/Schedules/ScheduleTriggerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ScheduleTriggerOptions
2323
/// <returns>A shallow copy of these options and any transitive options fields.</returns>
2424
public virtual object Clone()
2525
{
26-
var copy = (WorkflowOptions)MemberwiseClone();
26+
var copy = (ScheduleTriggerOptions)MemberwiseClone();
2727
if (Rpc != null)
2828
{
2929
copy.Rpc = (RpcOptions)Rpc.Clone();

src/Temporalio/Client/WorkflowCancelOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class WorkflowCancelOptions : ICloneable
1818
/// <returns>A shallow copy of these options and any transitive options fields.</returns>
1919
public virtual object Clone()
2020
{
21-
var copy = (WorkflowSignalOptions)MemberwiseClone();
21+
var copy = (WorkflowCancelOptions)MemberwiseClone();
2222
if (Rpc != null)
2323
{
2424
copy.Rpc = (RpcOptions)Rpc.Clone();

src/Temporalio/Client/WorkflowHistoryFetchOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class WorkflowHistoryFetchOptions : ICloneable
3131
/// <returns>A shallow copy of these options and any transitive options fields.</returns>
3232
public virtual object Clone()
3333
{
34-
var copy = (WorkflowHistoryEventFetchOptions)MemberwiseClone();
34+
var copy = (WorkflowHistoryFetchOptions)MemberwiseClone();
3535
if (Rpc != null)
3636
{
3737
copy.Rpc = (RpcOptions)Rpc.Clone();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace Temporalio.Tests;
2+
3+
using System.Reflection;
4+
using Xunit;
5+
using Xunit.Abstractions;
6+
7+
public class GeneralTests : TestBase
8+
{
9+
public GeneralTests(ITestOutputHelper output)
10+
: base(output)
11+
{
12+
}
13+
14+
[Fact]
15+
public void CloneableTypes_InstantiateAndClone_Succeeds()
16+
{
17+
// Walk Temporal assemblies finding all classes that are cloneable
18+
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes().Where(t =>
19+
t.IsClass &&
20+
t.Namespace is { } ns &&
21+
ns.StartsWith("Temporalio.") &&
22+
!ns.StartsWith("Temporalio.Api.") &&
23+
!ns.StartsWith("Temporalio.Bridge.") &&
24+
t.GetMethod("Clone", BindingFlags.Public | BindingFlags.Instance) != null));
25+
// Ensure at least one we know of is there
26+
Assert.Contains(typeof(Temporalio.Client.Schedules.ScheduleListOptions), types);
27+
foreach (var type in types)
28+
{
29+
// Instantiate and attempt clone
30+
var noParamConstructor = type.GetConstructors().
31+
First(c => c.GetParameters().All(p => p.IsOptional));
32+
var instance = noParamConstructor.Invoke(noParamConstructor.GetParameters()
33+
.Select(p => p.DefaultValue)
34+
.ToArray());
35+
var clone = type.GetMethod("Clone")!.Invoke(instance, null);
36+
Assert.IsType(type, clone);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)