Permalink
Browse files

Fixed the generated C# when an template value is returned.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Aug 5, 2017
1 parent aab4e65 commit 9fdb9a3dc212f0796b04278adbc9fff9a4973ebe
@@ -292,8 +292,12 @@ public override bool VisitClassDecl(Class @class)
if (returnType.IsAddress())
Context.Return.Write(HandleReturnedPointer(@class, qualifiedClass.Type));
else
Context.Return.Write("{0}.{1}({2})", qualifiedClass, Helpers.CreateInstanceIdentifier, Context.ReturnVarName);
Context.Return.Write($"{qualifiedClass}.{Helpers.CreateInstanceIdentifier}({Context.ReturnVarName})");
var finalType = (returnType.GetFinalPointee() ?? returnType).Desugar();
Class returnedClass;
if (finalType.TryGetClass(out returnedClass) && returnedClass.IsDependent)
Context.Return.Write($" as {returnedClass.Visit(typePrinter)}");
return true;
}
@@ -373,13 +377,6 @@ private string HandleReturnedPointer(Class @class, string qualifiedClass)
Context.Before.WriteLine("else {0} = {1}.{2}({3});", ret, qualifiedClass,
Helpers.CreateInstanceIdentifier, Context.ReturnVarName);
}
Class returnedClass;
var pointee = Context.ReturnType.Type.Desugar().GetFinalPointee().Desugar();
if (pointee.TryGetClass(out returnedClass) && returnedClass.IsDependent)
{
var result = returnedClass.Visit(typePrinter);
return $"{ret} as {result}{result.NameSuffix}";
}
return ret;
}
@@ -788,6 +788,17 @@ public void TestReturnInjectedClass()
}
}
[Test]
public void TestReturnTemplateValue()
{
using (var dependentValueFields = new DependentValueFields<int>())
{
dependentValueFields.DependentValue = 10;
Assert.That(dependentValueFields.ReturnValue().DependentValue,
Is.EqualTo(dependentValueFields.DependentValue));
}
}
[Test]
public void TestAbstractImplementatonsInPrimaryAndSecondaryBases()
{
@@ -114,6 +114,7 @@ class DLL_API DependentValueFields
DependentValueFields();
~DependentValueFields();
DependentValueFields& returnInjectedClass();
DependentValueFields returnValue();
T getDependentValue();
void setDependentValue(const T& value);
private:
@@ -151,6 +152,12 @@ DependentValueFields<T>& DependentValueFields<T>::returnInjectedClass()
return *this;
}
template <typename T>
DependentValueFields<T> DependentValueFields<T>::returnValue()
{
return *this;
}
template <typename T>
class DLL_API DependentPointerFields
{

0 comments on commit 9fdb9a3

Please sign in to comment.