Showing with 33 additions and 0 deletions.
  1. +14 −0 src/expression.d
  2. +19 −0 test/runnable/xtest46.d
14 changes: 14 additions & 0 deletions src/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -13936,11 +13936,15 @@ public:

override Expression semantic(Scope* sc)
{
if (type)
return this;

// same as for AndAnd
e1 = e1.semantic(sc);
e1 = resolveProperties(sc, e1);
e1 = e1.toBoolean(sc);
uint cs1 = sc.callSuper;

if (sc.flags & SCOPEcondition)
{
/* If in static if, don't evaluate e2 if we don't have to.
Expand All @@ -13951,9 +13955,11 @@ public:
return new IntegerExp(loc, 1, Type.tbool);
}
}

e2 = e2.semantic(sc);
sc.mergeCallSuper(loc, cs1);
e2 = resolveProperties(sc, e2);

if (e2.type.ty == Tvoid)
type = Type.tvoid;
else
Expand All @@ -13970,6 +13976,7 @@ public:
return e1;
if (e2.op == TOKerror)
return e2;

return this;
}

Expand Down Expand Up @@ -13997,11 +14004,15 @@ public:

override Expression semantic(Scope* sc)
{
if (type)
return this;

// same as for OrOr
e1 = e1.semantic(sc);
e1 = resolveProperties(sc, e1);
e1 = e1.toBoolean(sc);
uint cs1 = sc.callSuper;

if (sc.flags & SCOPEcondition)
{
/* If in static if, don't evaluate e2 if we don't have to.
Expand All @@ -14012,9 +14023,11 @@ public:
return new IntegerExp(loc, 0, Type.tbool);
}
}

e2 = e2.semantic(sc);
sc.mergeCallSuper(loc, cs1);
e2 = resolveProperties(sc, e2);

if (e2.type.ty == Tvoid)
type = Type.tvoid;
else
Expand All @@ -14031,6 +14044,7 @@ public:
return e1;
if (e2.op == TOKerror)
return e2;

return this;
}

Expand Down
19 changes: 19 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -7694,6 +7694,25 @@ void test15141()
assert(b is null); // OK <- oops
}

/***************************************************/
// 15366

enum E15366 : bool { A, B };

struct S15366
{
void func1(E15366 e) {}

void func2(E15366 a, E15366 b)
{
func1(cast(E15366)(a && b));
func1(cast(E15366)(a || b));

auto x1 = cast(E15366)(a && b);
auto x2 = cast(E15366)(a || b);
}
}

/***************************************************/

int main()
Expand Down