Skip to content

Commit

Permalink
Merge pull request #13493 from MoonlightSentinel/assert-boolean-conve…
Browse files Browse the repository at this point in the history
…rsion

Replace usages of Optional.hasValue(...) assuming a value with get()

Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com>
Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Jan 4, 2022
2 parents b4a4539 + 48005b9 commit b14861d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
11 changes: 3 additions & 8 deletions src/dmd/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,13 @@ UnionExp Not(Type type, Expression e1)
{
UnionExp ue = void;
Loc loc = e1.loc;
// BUG: Should be replaced with e1.toBool().get(), but this is apparently
// executed for some expressions that cannot be const-folded
// To be fixed in another PR
emplaceExp!(IntegerExp)(&ue, loc, e1.toBool().hasValue(false) ? 1 : 0, type);
return ue;
}

private UnionExp Bool(Type type, Expression e1)
{
UnionExp ue = void;
Loc loc = e1.loc;
emplaceExp!(IntegerExp)(&ue, loc, e1.toBool().hasValue(true) ? 1 : 0, type);
return ue;
}

UnionExp Add(const ref Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue = void;
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/optimize.d
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,8 @@ Expression Expression_optimize(Expression e, int result, bool keepLvalue)
const e1Opt = e.e1.toBool();
if (e.e2.isConst())
{
bool n1 = e1Opt.hasValue(true);
bool n2 = e.e2.toBool().hasValue(true);
bool n1 = e1Opt.get();
bool n2 = e.e2.toBool().get();
ret = new IntegerExp(e.loc, oror ? (n1 || n2) : (n1 && n2), e.type);
}
else if (e1Opt.hasValue(!oror))
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
e.error("`bool` expected as third argument of `__traits(getOverloads)`, not `%s` of type `%s`", b.toChars(), b.type.toChars());
return ErrorExp.get();
}
includeTemplates = b.toBool().hasValue(true);
includeTemplates = b.toBool().get();
}

StringExp se = ex.toStringExp();
Expand Down

0 comments on commit b14861d

Please sign in to comment.