Permalink
Browse files

Fixed the generated C# when returning a template with a renamed type …

…arg.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Aug 11, 2017
1 parent e0816d9 commit 2bff7a3caa6729e7388dd4d684fcf7bb8a522659
Showing with 51 additions and 29 deletions.
  1. +1 −1 src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. +15 −0 tests/CSharp/CSharp.Tests.cs
  3. +35 −28 tests/CSharp/CSharpTemplates.h
@@ -297,7 +297,7 @@ public override bool VisitClassDecl(Class @class)
var finalType = (returnType.GetFinalPointee() ?? returnType).Desugar();
Class returnedClass;
if (finalType.TryGetClass(out returnedClass) && returnedClass.IsDependent)
Context.Return.Write($" as {returnedClass.Visit(typePrinter)}");
Context.Return.Write($" as {returnType.Visit(typePrinter)}");
return true;
}
@@ -816,6 +816,21 @@ public void TestOperatorReturnTemplateValue()
}
}
[Test]
public void TestReturnTemplateWithRenamedTypeArg()
{
using (var dependentValueFields = new DependentValueFields<int>())
{
dependentValueFields.DependentValue = 10;
using (var hasDefaultTemplateArgument = new HasDefaultTemplateArgument<int, int>())
{
var returnTemplateWithRenamedTypeArg =
hasDefaultTemplateArgument.ReturnTemplateWithRenamedTypeArg(dependentValueFields);
Assert.That(returnTemplateWithRenamedTypeArg.DependentValue, Is.EqualTo(10));
}
}
}
[Test]
public void TestAbstractImplementatonsInPrimaryAndSecondaryBases()
{
@@ -205,6 +205,7 @@ class HasDefaultTemplateArgument
static T staticProperty();
static void setStaticProperty(const T& t);
bool operator==(const HasDefaultTemplateArgument& other);
DependentValueFields<D> returnTemplateWithRenamedTypeArg(const DependentValueFields<D> &value);
private:
T field;
static T staticField;
@@ -225,34 +226,6 @@ class HasDefaultTemplateArgument<bool, bool>
static bool staticField;
};
template <typename T>
class TemplateWithIndexer
{
public:
TemplateWithIndexer();
T& operator[](int i);
T& operator[](const char* string);
private:
T t[1];
};
template <typename T>
TemplateWithIndexer<T>::TemplateWithIndexer()
{
}
template <typename T>
T& TemplateWithIndexer<T>::operator[](int i)
{
return t[0];
}
template <typename T>
T& TemplateWithIndexer<T>::operator[](const char* string)
{
return t[0];
}
template <typename T, typename D>
HasDefaultTemplateArgument<T, D>::HasDefaultTemplateArgument()
{
@@ -293,9 +266,43 @@ bool HasDefaultTemplateArgument<T, D>::operator==(const HasDefaultTemplateArgume
return field == other.field;
}
template <typename T, typename D>
DependentValueFields<D> HasDefaultTemplateArgument<T, D>::returnTemplateWithRenamedTypeArg(const DependentValueFields<D>& value)
{
return value;
}
template <typename T, typename D>
T HasDefaultTemplateArgument<T, D>::staticField;
template <typename T>
class TemplateWithIndexer
{
public:
TemplateWithIndexer();
T& operator[](int i);
T& operator[](const char* string);
private:
T t[1];
};
template <typename T>
TemplateWithIndexer<T>::TemplateWithIndexer()
{
}
template <typename T>
T& TemplateWithIndexer<T>::operator[](int i)
{
return t[0];
}
template <typename T>
T& TemplateWithIndexer<T>::operator[](const char* string)
{
return t[0];
}
template <typename T>
class VirtualTemplate
{

0 comments on commit 2bff7a3

Please sign in to comment.