Skip to content

Commit a242bc8

Browse files
committed
Fixed the generated C# when a default arg is assigned a specialisation also used as a secondary base.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent ae9eede commit a242bc8

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

Diff for: src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public string VisitParameter(Parameter parameter)
2929
(parameter.DefaultArgument.Declaration != null ||
3030
parameter.DefaultArgument.Class == StatementClass.BinaryOperator))
3131
return $"({desugared.Visit(typePrinter)}) {expression}";
32+
Class @class;
33+
if (desugared.TryGetClass(out @class) && @class.IsInterface)
34+
return $@"({@class.Visit(typePrinter)}) ({
35+
@class.OriginalClass.Visit(typePrinter)}) {expression}";
3236
return expression;
3337
}
3438

Diff for: src/Generator/Generators/CSharp/CSharpSources.cs

+3-14
Original file line numberDiff line numberDiff line change
@@ -2338,9 +2338,7 @@ public void GenerateMethod(Method method, Class @class)
23382338
if (method.SynthKind == FunctionSynthKind.DefaultValueOverload)
23392339
{
23402340
if (!method.IsConstructor)
2341-
{
23422341
GenerateOverloadCall(method);
2343-
}
23442342
goto SkipImpl;
23452343
}
23462344

@@ -2439,8 +2437,7 @@ private string OverloadParamNameWithDefValue(Parameter p, ref int index)
24392437
Class @class;
24402438
return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue
24412439
? "ref param" + index++
2442-
: (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++
2443-
: ExpressionPrinter.VisitParameter(p));
2440+
: ExpressionPrinter.VisitParameter(p);
24442441
}
24452442

24462443
private void GenerateOverloadCall(Function function)
@@ -2454,16 +2451,8 @@ private void GenerateOverloadCall(Function function)
24542451
parameter.Usage == ParameterUsage.InOut && parameter.HasDefaultValue)
24552452
{
24562453
var pointeeType = ((PointerType) parameter.Type).Pointee.ToString();
2457-
WriteLine("{0} param{1} = {2};", pointeeType, j++,
2458-
primitiveType == PrimitiveType.Bool ? "false" : "0");
2459-
}
2460-
Class @class;
2461-
if (parameter.Kind == ParameterKind.Regular && parameter.Ignore &&
2462-
parameter.Type.Desugar().TryGetClass(out @class) && @class.IsInterface &&
2463-
parameter.HasDefaultValue)
2464-
{
2465-
WriteLine("var param{0} = ({1}) {2};", j++, @class.OriginalClass.OriginalName,
2466-
ExpressionPrinter.VisitParameter(parameter));
2454+
WriteLine($@"{pointeeType} param{j++} = {
2455+
(primitiveType == PrimitiveType.Bool ? "false" : "0")};");
24672456
}
24682457
}
24692458

0 commit comments

Comments
 (0)