Skip to content

Commit 469ea57

Browse files
committed
Fixing IL generation on out/ref parameter result assignment
1 parent ecd76ac commit 469ea57

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/WebJobs.Script/Description/FunctionGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static Type Generate(string functionAssemblyName, string typeName, Collec
127127
il.Emit(OpCodes.Ldelem_Ref);
128128
il.Emit(OpCodes.Castclass, param.Type.GetElementType());
129129

130-
il.Emit(OpCodes.Stind_Ref, i);
130+
il.Emit(OpCodes.Stind_Ref);
131131
}
132132

133133
il.Emit(OpCodes.Ret);

test/WebJobs.Script.Tests/FunctionGeneratorTests.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task Generate_EndToEnd()
2525
ConstructorInfo ctorInfo = typeof(TimerTriggerAttribute).GetConstructor(new Type[] { typeof(string) });
2626
PropertyInfo runOnStartupProperty = typeof(TimerTriggerAttribute).GetProperty("RunOnStartup");
2727
CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(
28-
ctorInfo,
28+
ctorInfo,
2929
new object[] { "00:00:02" },
3030
new PropertyInfo[] { runOnStartupProperty },
3131
new object[] { true });
@@ -63,5 +63,42 @@ public async Task Generate_EndToEnd()
6363
// verify our custom invoker was called
6464
Assert.True(invoker.InvokeCount >= 2);
6565
}
66+
67+
[Fact]
68+
public void Generate_WithMultipleOutParameters()
69+
{
70+
string functionName = "FunctionWithOuts";
71+
Collection<ParameterDescriptor> parameters = new Collection<ParameterDescriptor>();
72+
73+
parameters.Add(new ParameterDescriptor("param1", typeof(string)));
74+
parameters.Add(new ParameterDescriptor("param2", typeof(string).MakeByRefType()) { Attributes = ParameterAttributes.Out });
75+
parameters.Add(new ParameterDescriptor("param3", typeof(string).MakeByRefType()) { Attributes = ParameterAttributes.Out });
76+
77+
FunctionMetadata metadata = new FunctionMetadata();
78+
TestInvoker invoker = new TestInvoker();
79+
FunctionDescriptor function = new FunctionDescriptor(functionName, invoker, metadata, parameters);
80+
Collection<FunctionDescriptor> functions = new Collection<FunctionDescriptor>();
81+
functions.Add(function);
82+
83+
// generate the Type
84+
Type functionType = FunctionGenerator.Generate("TestScriptHost", "TestFunctions", functions);
85+
86+
// verify the generated function
87+
MethodInfo method = functionType.GetMethod(functionName);
88+
ParameterInfo[] functionParams = method.GetParameters();
89+
90+
// Verify that we have the correct number of parameters
91+
Assert.Equal(parameters.Count, functionParams.Length);
92+
93+
// Verify that out parameters were correctly generated
94+
Assert.True(functionParams[1].IsOut);
95+
Assert.True(functionParams[2].IsOut);
96+
97+
// Verify that the method is invocable
98+
method.Invoke(null, new object[] { "test", null, null });
99+
100+
// verify our custom invoker was called
101+
Assert.Equal(1, invoker.InvokeCount);
102+
}
66103
}
67104
}

0 commit comments

Comments
 (0)