Skip to content

Commit

Permalink
fix Issue 17145 - [REG2.066.0] Tuple expansion error in local enum de…
Browse files Browse the repository at this point in the history
…claration
  • Loading branch information
WalterBright committed Feb 9, 2020
1 parent 8a7650e commit 9930339
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/dmd/sideeffect.d
Expand Up @@ -390,7 +390,16 @@ VarDeclaration copyToTemp(StorageClass stc, const char[] name, Expression e)
Expression extractSideEffect(Scope* sc, const char[] name,
ref Expression e0, Expression e, bool alwaysCopy = false)
{
if (!alwaysCopy && isTrivialExp(e))
//printf("extractSideEffect(e: %s)\n", e.toChars());

/* The trouble here is that if CTFE is running, extracting the side effect
* results in an assignment, and then the interpreter says it cannot evaluate the
* side effect assignment variable. But we don't have to worry about side
* effects in function calls anyway, because then they won't CTFE.
* https://issues.dlang.org/show_bug.cgi?id=17145
*/
if (!alwaysCopy &&
(sc.flags & SCOPE.ctfe) ? !hasSideEffect(e) : isTrivialExp(e))
return e;

auto vd = copyToTemp(0, name, e);
Expand Down
13 changes: 13 additions & 0 deletions test/compilable/fix17145.d
@@ -0,0 +1,13 @@
// https://issues.dlang.org/show_bug.cgi?id=17145

auto tuple(T...)(T t) {
struct Result {
T expand;
}
return Result(t);
}

void baz()
{
enum zoo = tuple(1, 2).expand; // Error: value of __tup1847 is not known at compile time
}

0 comments on commit 9930339

Please sign in to comment.