Fixed up function template inference to handle pointer to template types
This commit is contained in:
@@ -1022,11 +1022,22 @@ void ASTTransformation::unifyType(NodeTree<Symbol> *syntaxType, Type type, std::
|
|||||||
// doesn't matter b/c it'll get filterd out in unifyTemplateFunction
|
// doesn't matter b/c it'll get filterd out in unifyTemplateFunction
|
||||||
// b) instantiated with a template type type (i.e. vector<T>)
|
// b) instantiated with a template type type (i.e. vector<T>)
|
||||||
// this will be a bit of a pain too
|
// this will be a bit of a pain too
|
||||||
|
// 4) This is a pointer type, go down a pointer level
|
||||||
|
|
||||||
auto children = syntaxType->getChildren();
|
auto children = syntaxType->getChildren();
|
||||||
if (children.size() == 1) {
|
if (children.size() == 1) {
|
||||||
(*templateTypeMap)[concatSymbolTree(children.back())] = type;
|
(*templateTypeMap)[concatSymbolTree(children.back())] = type;
|
||||||
} else {
|
} 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) {
|
if (type.typeDefinition) {
|
||||||
// ok, what happens here is that we get the origional type from our type. This is
|
// 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
|
// the same as the type we have now but it still has extra data from when it was instantiated
|
||||||
|
|||||||
1
tests/test_functionTemplateInference.expected_results
Normal file
1
tests/test_functionTemplateInference.expected_results
Normal file
@@ -0,0 +1 @@
|
|||||||
|
8
|
||||||
12
tests/test_functionTemplateInference.krak
Normal file
12
tests/test_functionTemplateInference.krak
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import io:*
|
||||||
|
|
||||||
|
fun ptrFn<T>(ptr: T*):void {
|
||||||
|
println(*ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main():int {
|
||||||
|
var a = 8
|
||||||
|
ptrFn(&a)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user