Skip to content

Commit 4671bd9

Browse files
committed
Allowing MethodCall to be aware of multiple variables of the same type within a Tuple. Bumps to 3.5.1
1 parent b7ee2ff commit 4671bd9

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
33
<PropertyGroup>
4-
<VersionPrefix>3.5.0</VersionPrefix>
4+
<VersionPrefix>3.5.1</VersionPrefix>
55
<LangVersion>10.0</LangVersion>
66
<Authors>Jeremy D. Miller;Babu Annamalai;Oskar Dudycz;Joona-Pekka Kokko</Authors>
77
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>

src/CodegenTests/Codegen/MethodCallTester.cs

+19
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ public void try_to_assign_variable_within_tuple()
348348
tuple.Inners[1].Inner.ShouldBeSameAs(ball);
349349
tuple.Inners[1].Action.ShouldBe(ReturnAction.Assign);
350350
}
351+
352+
[Fact]
353+
public void tuple_of_same_type()
354+
{
355+
var methodCall = MethodCall.For<MethodCallTarget>(x => x.TupleOfSame());
356+
methodCall.Creates.Count().ShouldBe(2);
357+
methodCall.Creates.ElementAt(0).Usage.ShouldBe("martenOp");
358+
methodCall.Creates.ElementAt(1).Usage.ShouldBe("martenOp2");
359+
}
351360
}
352361

353362
public class Ball
@@ -434,4 +443,14 @@ public Task<string> GetString()
434443
{
435444
return Task.FromResult("foo");
436445
}
446+
447+
public (IMartenOp, IMartenOp) TupleOfSame()
448+
{
449+
return (default, default);
450+
}
451+
}
452+
453+
public interface IMartenOp
454+
{
455+
437456
}

src/JasperFx.CodeGeneration/Frames/MethodCall.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public MethodCall(Type handlerType, MethodInfo method) : base(method.IsAsync())
5454

5555
if (ReturnType.IsValueTuple())
5656
{
57-
var values = ReturnType.GetGenericArguments().Select(x => new Variable(x, this)).ToArray();
57+
var values = buildTupleCreateVariables().ToArray();
5858

5959
ReturnVariable = new ValueTypeReturnVariable(ReturnType, values);
6060
}
@@ -87,7 +87,19 @@ public MethodCall(Type handlerType, MethodInfo method) : base(method.IsAsync())
8787
}
8888
}
8989
}
90-
90+
91+
private IEnumerable<Variable> buildTupleCreateVariables()
92+
{
93+
foreach (var type in ReturnType.GetGenericArguments())
94+
{
95+
var count = Creates.Count(x => x.VariableType == type);
96+
var suffix = count > 0 ? (count + 1).ToString() : string.Empty;
97+
var created = new Variable(type, Variable.DefaultArgName(type) + suffix, this);
98+
99+
yield return created;
100+
}
101+
}
102+
91103
/// <summary>
92104
/// Does this MethodCall create a new variable of the object type? This includes the return variable, destructuring
93105
/// tuples, or out parameters

0 commit comments

Comments
 (0)