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 a242bc8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public string VisitParameter(Parameter parameter)
(parameter.DefaultArgument.Declaration != null ||
parameter.DefaultArgument.Class == StatementClass.BinaryOperator))
return $"({desugared.Visit(typePrinter)}) {expression}";
Class @class;
if (desugared.TryGetClass(out @class) && @class.IsInterface)
return $@"({@class.Visit(typePrinter)}) ({
@class.OriginalClass.Visit(typePrinter)}) {expression}";
return expression;
}

Expand Down
17 changes: 3 additions & 14 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 @@ -2439,8 +2437,7 @@ 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 +2451,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 a242bc8

Please sign in to comment.