Skip to content

Commit 08bebbb

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 08bebbb

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public string VisitParameter(Parameter parameter)
2929
(parameter.DefaultArgument.Declaration != null ||
3030
parameter.DefaultArgument.Class == StatementClass.BinaryOperator))
3131
return $"({desugared.Visit(typePrinter)}) {expression}";
32+
var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar();
33+
Class @class;
34+
if (finalType.TryGetClass(out @class) && @class.IsInterface)
35+
return $@"({@class.Visit(typePrinter)}) ({
36+
@class.OriginalClass.Visit(typePrinter)}) {expression}";
3237
return expression;
3338
}
3439

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 3 additions & 15 deletions
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

@@ -2436,11 +2434,9 @@ private void GenerateMethodBody(Class @class, Method method,
24362434

24372435
private string OverloadParamNameWithDefValue(Parameter p, ref int index)
24382436
{
2439-
Class @class;
24402437
return p.Type.IsPointerToPrimitiveType() && p.Usage == ParameterUsage.InOut && p.HasDefaultValue
24412438
? "ref param" + index++
2442-
: (( p.Type.TryGetClass(out @class) && @class.IsInterface) ? "param" + index++
2443-
: ExpressionPrinter.VisitParameter(p));
2439+
: ExpressionPrinter.VisitParameter(p);
24442440
}
24452441

24462442
private void GenerateOverloadCall(Function function)
@@ -2454,16 +2450,8 @@ private void GenerateOverloadCall(Function function)
24542450
parameter.Usage == ParameterUsage.InOut && parameter.HasDefaultValue)
24552451
{
24562452
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));
2453+
WriteLine($@"{pointeeType} param{j++} = {
2454+
(primitiveType == PrimitiveType.Bool ? "false" : "0")};");
24672455
}
24682456
}
24692457

0 commit comments

Comments
 (0)