PR suggestion for returnType using addTypeToLookups
This commit is contained in:
parent
d4759480db
commit
9b120bb5f2
|
|
@ -151,13 +151,7 @@ final class FirstPass : ASTVisitor
|
|||
}
|
||||
|
||||
if (dec.returnType !is null){
|
||||
|
||||
// Do lookup if return type exists
|
||||
auto app = appender!string();
|
||||
app.formatNode(dec.returnType);
|
||||
|
||||
currentSymbol.typeLookups.insert(TypeLookupsAllocator.instance.make!TypeLookup(
|
||||
istring(app.data), TypeLookupKind.returnType));
|
||||
addTypeToLookups(currentSymbol.typeLookups, dec.returnType);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -311,25 +311,6 @@ do
|
|||
|
||||
private:
|
||||
|
||||
void resolveReturnType(DSymbol* symbol, ref TypeLookups typeLookups,
|
||||
Scope* moduleScope, ref ModuleCache cache)
|
||||
{
|
||||
foreach (returnType; typeLookups[].filter!(a => a.kind == TypeLookupKind.returnType))
|
||||
{
|
||||
assert(returnType.breadcrumbs.length > 0);
|
||||
auto parts = symbol.getPartsByName(returnType.breadcrumbs.front);
|
||||
if (parts.empty){
|
||||
// If nothing found try to lookup within the global scope
|
||||
auto found = moduleScope.getSymbolsAtGlobalScope(returnType.breadcrumbs.front);
|
||||
if (!found.empty) {
|
||||
symbol.returnType = found.front;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void resolveInheritance(DSymbol* symbol, ref TypeLookups typeLookups,
|
||||
Scope* moduleScope, ref ModuleCache cache)
|
||||
{
|
||||
|
|
@ -437,9 +418,6 @@ void resolveType(DSymbol* symbol, ref TypeLookups typeLookups,
|
|||
// issue 94
|
||||
else if (lookup.kind == TypeLookupKind.inherit)
|
||||
resolveInheritance(symbol, typeLookups, moduleScope, cache);
|
||||
else if (lookup.kind == TypeLookupKind.returnType){
|
||||
resolveReturnType(symbol, typeLookups, moduleScope, cache);
|
||||
}
|
||||
else
|
||||
assert(false, "How did this happen?");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ unittest
|
|||
auto source = q{ int meaningOfLife() { return 42; } };
|
||||
auto pair = generateAutocompleteTrees(source, cache);
|
||||
auto meaningOfLife = pair.symbol.getFirstPartNamed(istring("meaningOfLife"));
|
||||
assert(meaningOfLife.returnType.name == "int");
|
||||
assert(meaningOfLife.type.name == "int");
|
||||
}
|
||||
|
||||
unittest
|
||||
|
|
@ -144,7 +144,7 @@ unittest
|
|||
auto pair = generateAutocompleteTrees(source, cache);
|
||||
auto lifeClass = pair.symbol.getFirstPartNamed(istring("Life"));
|
||||
auto meaningOfLife = lifeClass.getFirstPartNamed(istring("meaningOfLife"));
|
||||
assert(meaningOfLife.returnType.name == "uint");
|
||||
assert(meaningOfLife.type.name == "uint");
|
||||
}
|
||||
|
||||
unittest
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ enum TypeLookupKind : ubyte
|
|||
mixinTemplate,
|
||||
varOrFunType,
|
||||
selectiveImport,
|
||||
returnType,
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue