mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Add supplemental scope info to mixin T; errors
Fix issue 7372 - Error provides too little information to diagnose the problem (error: undefined identifier) Mixin templates are often defined inside libraries and may require the definition of certain symbols alongside them (for example a text templating library mapping struct fields to HTML text blocks could attempt to simply access member variables) - Fixing compilation errors where such identifiers are not found would then usually not require code changes inside the library, but rather in the user code, where the mixin is written. So this PR adds a supplemental `parent scope from here: '...'` message, which may be used from IDEs to show errors on the mixin line or just for the user to read it in the command line and see where in the user code the error originates from.
This commit is contained in:
parent
de06d6a51a
commit
f01795072b
4 changed files with 33 additions and 2 deletions
|
@ -167,11 +167,18 @@ private extern(C++) final class Semantic3Visitor : Visitor
|
|||
|
||||
sc = sc.push(tmix.argsym);
|
||||
sc = sc.push(tmix);
|
||||
|
||||
uint olderrors = global.errors;
|
||||
|
||||
for (size_t i = 0; i < tmix.members.dim; i++)
|
||||
{
|
||||
Dsymbol s = (*tmix.members)[i];
|
||||
s.semantic3(sc);
|
||||
}
|
||||
|
||||
if (global.errors != olderrors)
|
||||
errorSupplemental(tmix.loc, "parent scope from here: `mixin %s`", tmix.toChars());
|
||||
|
||||
sc = sc.pop();
|
||||
sc.pop();
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/diag13528.d(13): Error: value of `this` is not known at compile time
|
||||
fail_compilation/diag13528.d(13): while evaluating `pragma(msg, __traits(getMember, A, "foo"))`
|
||||
fail_compilation/diag13528.d(6): Error: value of `this` is not known at compile time
|
||||
fail_compilation/diag13528.d(6): while evaluating `pragma(msg, __traits(getMember, A, "foo"))`
|
||||
fail_compilation/diag13528.d(12): parent scope from here: `mixin MyTemplate!()`
|
||||
---
|
||||
*/
|
||||
#line 1
|
||||
|
||||
mixin template MyTemplate()
|
||||
{
|
||||
|
|
13
compiler/test/fail_compilation/fail7372.d
Normal file
13
compiler/test/fail_compilation/fail7372.d
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/imports/fail7372.d(7): Error: undefined identifier `X`
|
||||
fail_compilation/fail7372.d(4): parent scope from here: `mixin Issue7372!()`
|
||||
---
|
||||
*/
|
||||
#line 1
|
||||
import imports.fail7372;
|
||||
interface I {}
|
||||
class C : I {
|
||||
mixin Issue7372!();
|
||||
}
|
9
compiler/test/fail_compilation/imports/fail7372.d
Normal file
9
compiler/test/fail_compilation/imports/fail7372.d
Normal file
|
@ -0,0 +1,9 @@
|
|||
module imports.fail7372;
|
||||
import imports.imp1;
|
||||
mixin template Issue7372()
|
||||
{
|
||||
public void f()
|
||||
{
|
||||
int foo = X;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue