From 365e8d676241eae00b3ed47ab4a9da2b5f3fcea0 Mon Sep 17 00:00:00 2001 From: ryuukk <44361234+ryuukk@users.noreply.github.com> Date: Thu, 13 Oct 2022 19:38:18 +0200 Subject: [PATCH] Use crumb to get return type of a templated function --- dsymbol/src/dsymbol/conversion/second.d | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/dsymbol/src/dsymbol/conversion/second.d b/dsymbol/src/dsymbol/conversion/second.d index bd56763..00c5690 100644 --- a/dsymbol/src/dsymbol/conversion/second.d +++ b/dsymbol/src/dsymbol/conversion/second.d @@ -432,15 +432,29 @@ void resolveTypeFromInitializer(DSymbol* symbol, TypeLookup* lookup, size_t i = 0; auto crumbs = lookup.breadcrumbs[]; + auto bl = lookup.breadcrumbs.length; + bool isArray = lookup.breadcrumbs.back == ARRAY_LITERAL_SYMBOL_NAME || lookup.breadcrumbs.back == ARRAY_SYMBOL_NAME; foreach (crumb; crumbs) { - if (i == 0) + // if the function has a crumb, then it could be a templated function or a cast, we can use that to guess the its Type + if (i == 0 || (!isArray && (i > 0 && bl > 1))) { currentSymbol = moduleScope.getFirstSymbolByNameAndCursor( symbolNameToTypeName(crumb), symbol.location); + // check if the type was already known + if (i == bl-2 && currentSymbol !is null && currentSymbol.type !is null) + { + if (moduleScope.hasSymbolRecursive(currentSymbol.type)) + break; + } + if (currentSymbol is null) - return; + continue; + else if (currentSymbol.type is null) + break; // this is a fully resolved type (casting)! + else if (currentSymbol.type.name == "void") + return; // it's void, no need to continue } else if (crumb == ARRAY_LITERAL_SYMBOL_NAME) @@ -506,9 +520,9 @@ void resolveTypeFromInitializer(DSymbol* symbol, TypeLookup* lookup, currentSymbol = currentSymbol.getFirstPartNamed(crumb); } ++i; - if (currentSymbol is null) - return; } + if (currentSymbol is null) + return; typeSwap(currentSymbol); symbol.type = currentSymbol; symbol.ownType = false;