Skip to content

Commit

Permalink
fix Issue 14731 - Error location insufficient when CTFE
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jun 25, 2015
1 parent 3c47713 commit 99b8bca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/interpret.c
Expand Up @@ -2982,6 +2982,9 @@ class Interpreter : public Visitor
if (exceptionOrCant(se))
return;
result = interpret(e->member, istate, e->arguments, se);

// Repaint as same as CallExp::interpret() does.
result->loc = e->loc;
}
else
{
Expand Down Expand Up @@ -3074,6 +3077,12 @@ class Interpreter : public Visitor
Expression *ctorfail = interpret(e->member, istate, e->arguments, eref);
if (exceptionOrCant(ctorfail))
return;

/* Bugzilla 14465: Repaint the loc, because a super() call
* in the constructor modifies the loc of ClassReferenceExp
* in CallExp::interpret().
*/
eref->loc = e->loc;
}
result = eref;
return;
Expand Down Expand Up @@ -4897,10 +4906,8 @@ class Interpreter : public Visitor
}
if (!exceptionOrCantInterpret(result))
{
Expression* old = result;
result = paintTypeOntoLiteral(e->type, result);
if (result != old) // only change location if a conversion was necessary
result->loc = e->loc;
result->loc = e->loc;
}
else if (CTFEExp::isCantExp(result) && !global.gag)
showCtfeBackTrace(e, fd); // Print a stack trace.
Expand Down
18 changes: 18 additions & 0 deletions test/fail_compilation/ctfe14731.d
@@ -0,0 +1,18 @@
/*
TEST_OUTPUT:
---
fail_compilation/ctfe14731.d(16): Error: cannot implicitly convert expression (["a b"]) of type string[] to string
fail_compilation/ctfe14731.d(17): Error: cannot implicitly convert expression (split("a b")) of type string[] to string
---
*/

string[] split(string a)
{
return [a];
}

void main()
{
enum string list1 = "a b".split();
string list2 = "a b".split();
}

0 comments on commit 99b8bca

Please sign in to comment.