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){
|
if (dec.returnType !is null){
|
||||||
|
addTypeToLookups(currentSymbol.typeLookups, dec.returnType);
|
||||||
// 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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -311,25 +311,6 @@ do
|
||||||
|
|
||||||
private:
|
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,
|
void resolveInheritance(DSymbol* symbol, ref TypeLookups typeLookups,
|
||||||
Scope* moduleScope, ref ModuleCache cache)
|
Scope* moduleScope, ref ModuleCache cache)
|
||||||
{
|
{
|
||||||
|
|
@ -437,9 +418,6 @@ void resolveType(DSymbol* symbol, ref TypeLookups typeLookups,
|
||||||
// issue 94
|
// issue 94
|
||||||
else if (lookup.kind == TypeLookupKind.inherit)
|
else if (lookup.kind == TypeLookupKind.inherit)
|
||||||
resolveInheritance(symbol, typeLookups, moduleScope, cache);
|
resolveInheritance(symbol, typeLookups, moduleScope, cache);
|
||||||
else if (lookup.kind == TypeLookupKind.returnType){
|
|
||||||
resolveReturnType(symbol, typeLookups, moduleScope, cache);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
assert(false, "How did this happen?");
|
assert(false, "How did this happen?");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ unittest
|
||||||
auto source = q{ int meaningOfLife() { return 42; } };
|
auto source = q{ int meaningOfLife() { return 42; } };
|
||||||
auto pair = generateAutocompleteTrees(source, cache);
|
auto pair = generateAutocompleteTrees(source, cache);
|
||||||
auto meaningOfLife = pair.symbol.getFirstPartNamed(istring("meaningOfLife"));
|
auto meaningOfLife = pair.symbol.getFirstPartNamed(istring("meaningOfLife"));
|
||||||
assert(meaningOfLife.returnType.name == "int");
|
assert(meaningOfLife.type.name == "int");
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
|
@ -144,7 +144,7 @@ unittest
|
||||||
auto pair = generateAutocompleteTrees(source, cache);
|
auto pair = generateAutocompleteTrees(source, cache);
|
||||||
auto lifeClass = pair.symbol.getFirstPartNamed(istring("Life"));
|
auto lifeClass = pair.symbol.getFirstPartNamed(istring("Life"));
|
||||||
auto meaningOfLife = lifeClass.getFirstPartNamed(istring("meaningOfLife"));
|
auto meaningOfLife = lifeClass.getFirstPartNamed(istring("meaningOfLife"));
|
||||||
assert(meaningOfLife.returnType.name == "uint");
|
assert(meaningOfLife.type.name == "uint");
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ enum TypeLookupKind : ubyte
|
||||||
mixinTemplate,
|
mixinTemplate,
|
||||||
varOrFunType,
|
varOrFunType,
|
||||||
selectiveImport,
|
selectiveImport,
|
||||||
returnType,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue