Skip to content

Commit

Permalink
Fixed the generated C# when a default arg is assigned a specialisatio…
Browse files Browse the repository at this point in the history
…n also used as a secondary base.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Dec 24, 2017
1 parent ae9eede commit 08bebbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
18 changes: 3 additions & 15 deletions src/Generator/Generators/CSharp/CSharpSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2338,9 +2338,7 @@ public void GenerateMethod(Method method, Class @class)
if (method.SynthKind == FunctionSynthKind.DefaultValueOverload)
{
if (!method.IsConstructor)
{
GenerateOverloadCall(method);
}
goto SkipImpl;
}

Expand Down Expand Up @@ -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)
Expand All @@ -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")};");
}
}

Expand Down

0 comments on commit 08bebbb

Please sign in to comment.