diff --git a/src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs b/src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs index 17e5619779..996648c9a6 100644 --- a/src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs @@ -29,6 +29,11 @@ public string VisitParameter(Parameter parameter) (parameter.DefaultArgument.Declaration != null || parameter.DefaultArgument.Class == StatementClass.BinaryOperator)) return $"({desugared.Visit(typePrinter)}) {expression}"; + var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar(); + Class @class; + if (finalType.TryGetClass(out @class) && @class.IsInterface) + return $@"({@class.Visit(typePrinter)}) ({ + @class.OriginalClass.Visit(typePrinter)}) {expression}"; return expression; } diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index 664d2090d4..db9755500f 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -2338,9 +2338,7 @@ public void GenerateMethod(Method method, Class @class) if (method.SynthKind == FunctionSynthKind.DefaultValueOverload) { if (!method.IsConstructor) - { GenerateOverloadCall(method); - } goto SkipImpl; } @@ -2436,11 +2434,9 @@ private void GenerateMethodBody(Class @class, Method method, private string OverloadParamNameWithDefValue(Parameter p, ref int index) { - Class @class; return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue ? "ref param" + index++ - : (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++ - : ExpressionPrinter.VisitParameter(p)); + : ExpressionPrinter.VisitParameter(p); } private void GenerateOverloadCall(Function function) @@ -2454,16 +2450,8 @@ private void GenerateOverloadCall(Function function) parameter.Usage == ParameterUsage.InOut && parameter.HasDefaultValue) { var pointeeType = ((PointerType) parameter.Type).Pointee.ToString(); - WriteLine("{0} param{1} = {2};", pointeeType, j++, - primitiveType == PrimitiveType.Bool ? "false" : "0"); - } - Class @class; - if (parameter.Kind == ParameterKind.Regular && parameter.Ignore && - parameter.Type.Desugar().TryGetClass(out @class) && @class.IsInterface && - parameter.HasDefaultValue) - { - WriteLine("var param{0} = ({1}) {2};", j++, @class.OriginalClass.OriginalName, - ExpressionPrinter.VisitParameter(parameter)); + WriteLine($@"{pointeeType} param{j++} = { + (primitiveType == PrimitiveType.Bool ? "false" : "0")};"); } }