From 7448a88f669823f180a773404504ce693bdf105f Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Sat, 23 May 2015 23:40:55 -0400 Subject: [PATCH] Fixed up function template inference to handle pointer to template types --- src/ASTTransformation.cpp | 11 +++++++++++ .../test_functionTemplateInference.expected_results | 1 + tests/test_functionTemplateInference.krak | 12 ++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/test_functionTemplateInference.expected_results create mode 100644 tests/test_functionTemplateInference.krak diff --git a/src/ASTTransformation.cpp b/src/ASTTransformation.cpp index 714a8e8..17e9b14 100644 --- a/src/ASTTransformation.cpp +++ b/src/ASTTransformation.cpp @@ -1022,11 +1022,22 @@ void ASTTransformation::unifyType(NodeTree *syntaxType, Type type, std:: // doesn't matter b/c it'll get filterd out in unifyTemplateFunction // b) instantiated with a template type type (i.e. vector) // this will be a bit of a pain too + // 4) This is a pointer type, go down a pointer level auto children = syntaxType->getChildren(); if (children.size() == 1) { (*templateTypeMap)[concatSymbolTree(children.back())] = type; } else { + // go down one in our pointer + if (children.back()->getDataRef()->getValue() == "*") { + // gotta be a better way to do this + Type* clonedType = type.clone(); + clonedType->decreaseIndirection(); + unifyType(children.front(), *clonedType, templateTypeMap); + delete clonedType; + return; + } + if (type.typeDefinition) { // ok, what happens here is that we get the origional type from our type. This is // the same as the type we have now but it still has extra data from when it was instantiated diff --git a/tests/test_functionTemplateInference.expected_results b/tests/test_functionTemplateInference.expected_results new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/tests/test_functionTemplateInference.expected_results @@ -0,0 +1 @@ +8 diff --git a/tests/test_functionTemplateInference.krak b/tests/test_functionTemplateInference.krak new file mode 100644 index 0000000..55e03d8 --- /dev/null +++ b/tests/test_functionTemplateInference.krak @@ -0,0 +1,12 @@ +import io:* + +fun ptrFn(ptr: T*):void { + println(*ptr) +} + +fun main():int { + var a = 8 + ptrFn(&a) + return 0 +} +