added template return type test and more

This commit is contained in:
davu 2023-03-05 01:33:50 +01:00
parent 3f921a0d76
commit ee6f8a867f
2 changed files with 50 additions and 3 deletions

View File

@ -375,9 +375,6 @@ struct DSymbol
// TODO: assert that the type is not a function // TODO: assert that the type is not a function
DSymbol* type; DSymbol* type;
// Return type symbol, if symbol currently is of function kind
DSymbol* returnType;
// Is alias this symbols // Is alias this symbols
DSymbol*[] aliasThisSymbols; DSymbol*[] aliasThisSymbols;
/** /**

View File

@ -169,6 +169,56 @@ unittest
assert(meaningOfLife.type is null); assert(meaningOfLife.type is null);
} }
unittest
{
ModuleCache cache;
writeln("Templated return type should be deduced correctly");
auto source = q{
struct AnswerToLife(T) {
T life;
}
AnswerToLife!int meaningOfLife() { return AnswerToLife!int(42); }
};
ScopeSymbolPair pair = generateAutocompleteTrees(source, cache);
auto answerToLife = pair.symbol.getFirstPartNamed(istring("AnswerToLife"));
DSymbol* meaningOfLife = pair.symbol.getFirstPartNamed(istring("meaningOfLife"));
assert(meaningOfLife.type.name == "AnswerToLife");
assert(meaningOfLife.type is answerToLife);
}
unittest
{
ModuleCache cache;
writeln("Array return type should be deduced correctly");
auto source = q{
int[] meaningOfLife() { return [42]; }
};
ScopeSymbolPair pair = generateAutocompleteTrees(source, cache);
DSymbol* meaningOfLife = pair.symbol.getFirstPartNamed(istring("meaningOfLife"));
assert(meaningOfLife.type.name == "*arr*");
}
unittest
{
ModuleCache cache;
writeln("Int* return type should be deduced correctly");
auto source = q{
int* meaningOfLife()
{
auto life = 42;
return &life;
}
};
ScopeSymbolPair pair = generateAutocompleteTrees(source, cache);
DSymbol* meaningOfLife = pair.symbol.getFirstPartNamed(istring("meaningOfLife"));
writeln(meaningOfLife.type.name);
assert(meaningOfLife.type.name == "int");
}
unittest unittest