Skip to content

Commit

Permalink
Clean up and fix bugs in boolean logic
Browse files Browse the repository at this point in the history
Signed-off-by: David Longnecker <dlongnecke-cray@users.noreply.github.com>
  • Loading branch information
dlongnecke-cray committed Sep 27, 2024
1 parent 435d487 commit 5ae1c06
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions frontend/lib/resolution/resolution-queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,16 @@ static void checkForParenlessMethodFieldRedefinition(Context* context,
}
}

// Returns 'true' if parent frames are present in the RC.
static bool checkIfParentFramesArePresent(ResolutionContext* rc,
// Returns 'true' and emits an error if parent frames are not in the RC.
static bool errorIfParentFramesNotPresent(ResolutionContext* rc,
const UntypedFnSignature* usig) {
Context* context = rc->context();
bool ret = !rc->isEmpty();

// TODO: More specifically, check if parent frames exist.
bool ret = rc->isEmpty();

// TODO: Becomes a structural issue after we pass in the parent.
if (!ret) {
if (ret) {
const ID& id = usig->id();
context->error(id, "stack frames for the parent of '%s' are not "
"present, so outer variables in its signature "
Expand Down Expand Up @@ -613,7 +615,7 @@ typedSignatureInitialImpl(ResolutionContext* rc,
CHPL_ASSERT(parentSignature);

// Outer variables can't be typed without stack frames, so give up.
if (!checkIfParentFramesArePresent(rc, untypedSig)) return nullptr;
if (errorIfParentFramesNotPresent(rc, untypedSig)) return nullptr;
}

// now, construct a TypedFnSignature from the result
Expand Down Expand Up @@ -641,7 +643,7 @@ typedSignatureInitialImpl(ResolutionContext* rc,
CHPL_ASSERT(parentSignature);

// Outer variables can't be typed without stack frames, so give up.
if (!checkIfParentFramesArePresent(rc, untypedSig)) return nullptr;
if (errorIfParentFramesNotPresent(rc, untypedSig)) return nullptr;
}

checkForParenlessMethodFieldRedefinition(context, fn, visitor);
Expand Down Expand Up @@ -2554,13 +2556,14 @@ resolveFunctionByInfoImpl(ResolutionContext* rc, const TypedFnSignature* sig,
PoiInfo resolvedPoiInfo;
ResolutionResultByPostorderID rr;

if (!fn->body() && !fn) {
CHPL_ASSERT(false && "Should only be called on functions!");
// TODO: Make sure the ID is an extern function specifically.
bool canResolveWithoutAst = parsing::idIsExtern(context, sig->id()) ||
sig->isInitializer();
if (!fn && !canResolveWithoutAst) {
CHPL_ASSERT(false && "Unexpected input to 'resolveFunction'!");
return nullptr;
}

const TypedFnSignature* finalSig = sig;

auto visitor = sig->isInitializer()
? Resolver::createForInitializer(rc, fn, poiScope, sig, rr)
: Resolver::createForFunction(rc, fn, poiScope, sig, rr);
Expand All @@ -2579,12 +2582,14 @@ resolveFunctionByInfoImpl(ResolutionContext* rc, const TypedFnSignature* sig,
return nullptr;
}

const TypedFnSignature* finalSig = sig;

// then, compute the return type if it is not an initializer
if (!sig->isInitializer()) {
computeReturnType(visitor);

// else, potentially write out a new initializer signature
} else if (visitor.initResolver) {
} else {
finalSig = visitor.initResolver->finalize();
}

Expand Down

0 comments on commit 5ae1c06

Please sign in to comment.