mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 05:30:13 +03:00
Fix Issues 23951 and 23279 - traits(hasMember) does not follow alias this + ICE when using traits(hasMember) on an erroneous member (#15406)
* Fix Issue 23951 - traits(getMember) does not follow alias this * Fix Issue 23279 - ICE when using traits(hasMember) with an erroneous member
This commit is contained in:
parent
8094a01e43
commit
452e170d2a
3 changed files with 39 additions and 6 deletions
|
@ -947,15 +947,24 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
|
|||
*/
|
||||
|
||||
Dsymbol sym = getDsymbol(o);
|
||||
|
||||
if (sym && e.ident == Id.hasMember)
|
||||
{
|
||||
if (auto sm = sym.search(e.loc, id))
|
||||
return True();
|
||||
|
||||
// https://issues.dlang.org/show_bug.cgi?id=23951
|
||||
if (auto decl = sym.isDeclaration())
|
||||
{
|
||||
ex = typeDotIdExp(e.loc, decl.type, id);
|
||||
goto doSemantic;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto t = isType(o))
|
||||
ex = typeDotIdExp(e.loc, t, id);
|
||||
else if (sym)
|
||||
{
|
||||
if (e.ident == Id.hasMember)
|
||||
{
|
||||
if (auto sm = sym.search(e.loc, id))
|
||||
return True();
|
||||
}
|
||||
ex = new DsymbolExp(e.loc, sym);
|
||||
ex = new DotIdExp(e.loc, ex, id);
|
||||
}
|
||||
|
@ -966,7 +975,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
|
|||
e.error("invalid first argument");
|
||||
return ErrorExp.get();
|
||||
}
|
||||
|
||||
doSemantic:
|
||||
// ignore symbol visibility and disable access checks for these traits
|
||||
Scope* scx = sc.push();
|
||||
scx.flags |= SCOPE.ignoresymbolvisibility | SCOPE.noaccesscheck;
|
||||
|
|
10
compiler/test/compilable/test23951.d
Normal file
10
compiler/test/compilable/test23951.d
Normal file
|
@ -0,0 +1,10 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=23951
|
||||
|
||||
struct S { int x; }
|
||||
struct T { S a; alias a this; }
|
||||
struct U { T t; }
|
||||
static assert(__traits(hasMember, T, "x"));
|
||||
static assert(__traits(hasMember, T.init, "x"));
|
||||
static assert(__traits(hasMember, U.init.t, "x"));
|
||||
static assert(__traits(hasMember, U.t, "a"));
|
||||
static assert(__traits(hasMember, U.t, "x"));
|
14
compiler/test/fail_compilation/test23279.d
Normal file
14
compiler/test/fail_compilation/test23279.d
Normal file
|
@ -0,0 +1,14 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=23279
|
||||
|
||||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/test23279.d(13): Error: undefined identifier `Sth`
|
||||
---
|
||||
*/
|
||||
|
||||
class Tester
|
||||
{
|
||||
enum a = __traits(hasMember, Tester, "setIt");
|
||||
void setIt(Sth sth){}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue