Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 5e8f72e

Browse files
Merge pull request #392 from xamarin/generic-tuple-test
wrap generic tuples
2 parents a92c91b + 259e118 commit 5e8f72e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

SwiftReflector/MethodWrapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@ SLFunc MapTopLevelFuncToWrapperFunc (SLImportModules modules, FunctionDeclaratio
18401840
parms.Insert (0, new SLParameter (returnName, newReturnType));
18411841
} else {
18421842
if (funcDecl.IsTypeSpecGeneric (retType)) {
1843-
if (retType.ContainsGenericParameters) {
1843+
if (retType.ContainsGenericParameters || retType is TupleTypeSpec) {
18441844
SLType retSLType = typeMapper.TypeSpecMapper.MapType (funcDecl, modules, retType, true);
18451845
parms.Insert (0, new SLParameter (returnName,
18461846
new SLBoundGenericType ("UnsafeMutablePointer", retSLType)));

tests/tom-swifty-test/SwiftReflector/GenericFunctionTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,31 @@ public init(value: T?) {
12831283
var callingCode = CSCodeBlock.Create (printIt);
12841284

12851285
TestRunning.TestAndExecute (swiftCode, callingCode, "compiled\n");
1286+
}
1287+
1288+
[Test]
1289+
public void TestGenericTuple ()
1290+
{
1291+
var swiftCode = @"
1292+
public func rotate<T>(x: (T, T, T)) -> (T, T, T)
1293+
{
1294+
return (x.1, x.2, x.0)
12861295
}
1296+
";
1297+
1298+
// var t = new Tuple<nint, nint, nint>(1, 2, 3)
1299+
// var u = TopLevelFunctions.Rotate(t);
1300+
// Console.WriteLine (u);
12871301

1302+
var tID = new CSIdentifier ("t");
1303+
var uID = new CSIdentifier ("u");
1304+
var tDecl = CSVariableDeclaration.VarLine (tID, new CSFunctionCall ("Tuple<nint, nint, nint>", true,
1305+
CSConstant.Val (1), CSConstant.Val (2), CSConstant.Val (3)));
1306+
var uDecl = CSVariableDeclaration.VarLine (uID, new CSFunctionCall ("TopLevelEntities.Rotate", false, tID));
1307+
var printer = CSFunctionCall.ConsoleWriteLine (uID);
1308+
var callingCode = CSCodeBlock.Create (tDecl, uDecl, printer);
1309+
1310+
TestRunning.TestAndExecute (swiftCode, callingCode, "(2, 3, 1)\n");
1311+
}
12881312
}
12891313
}

0 commit comments

Comments
 (0)