Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSymbol: ryuukk: Use crumb to get return type of a templated function #681

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions dsymbol/src/dsymbol/conversion/second.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down