Skip to content

Commit 4cb2e89

Browse files
committed
Remove redundant AssignArgumentStatement
... which only works correctly for by-refs and with `DefaultValue- Expression`
1 parent 47e9e69 commit 4cb2e89

File tree

4 files changed

+10
-66
lines changed

4 files changed

+10
-66
lines changed

src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/AssignArgumentStatement.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -42,34 +42,12 @@ public void Emit(ILGenerator gen)
4242
gen.Emit(OpCodes.Initobj, type);
4343
gen.Emit(OpCodes.Ldloc, local);
4444
}
45-
else if (type.IsByRef)
46-
{
47-
EmitByRef(gen);
48-
}
4945
else
5046
{
5147
throw new NotImplementedException("Can't emit default value for type " + type);
5248
}
5349
}
5450

55-
private void EmitByRef(ILGenerator gen)
56-
{
57-
var elementType = type.GetElementType();
58-
if (IsPrimitiveOrClass(elementType))
59-
{
60-
OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(gen, elementType);
61-
OpCodeUtil.EmitStoreIndirectOpCodeForType(gen, elementType);
62-
}
63-
else if (elementType.IsGenericParameter || elementType.IsValueType)
64-
{
65-
gen.Emit(OpCodes.Initobj, elementType);
66-
}
67-
else
68-
{
69-
throw new NotImplementedException("Can't emit default value for reference of type " + elementType);
70-
}
71-
}
72-
7351
private bool IsPrimitiveOrClass(Type type)
7452
{
7553
if (type.IsPrimitive && type != typeof(IntPtr) && type != typeof(UIntPtr))

src/Castle.Core/DynamicProxy/Generators/MinimalisticMethodGenerator.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2004-2021 Castle Project - http://www.castleproject.org/
1+
// Copyright 2004-2025 Castle Project - http://www.castleproject.org/
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -52,8 +52,10 @@ private void InitOutParameters(MethodEmitter emitter, ParameterInfo[] parameters
5252
if (parameter.IsOut)
5353
{
5454
emitter.CodeBuilder.AddStatement(
55-
new AssignArgumentStatement(new ArgumentReference(parameter.ParameterType, index + 1),
56-
new DefaultValueExpression(parameter.ParameterType)));
55+
new AssignStatement(
56+
new IndirectReference(
57+
new ArgumentReference(parameter.ParameterType, index + 1)),
58+
new DefaultValueExpression(parameter.ParameterType.GetElementType())));
5759
}
5860
}
5961
}

src/Castle.Core/DynamicProxy/Generators/OptionallyForwardingMethodGenerator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ private void InitOutParameters(BlockStatement statements, ParameterInfo[] parame
8484
if (parameter.IsOut)
8585
{
8686
statements.AddStatement(
87-
new AssignArgumentStatement(new ArgumentReference(parameter.ParameterType, index + 1),
88-
new DefaultValueExpression(parameter.ParameterType)));
87+
new AssignStatement(
88+
new IndirectReference(
89+
new ArgumentReference(parameter.ParameterType, index + 1)),
90+
new DefaultValueExpression(parameter.ParameterType.GetElementType())));
8991
}
9092
}
9193
}

0 commit comments

Comments
 (0)