Skip to content

Commit 3dd9769

Browse files
Fix Issue 22969 - Can't mixin name of manifest constant on right-handside of alias declaration (#13946)
Remove an unnecessary `typeToExpression` conversion call that forced `mixin` to be resolved via expression semantic (expanding enum constants when it shouldn't). This was a change I wanted to make some time ago but an early error somewhere in the type semantic prevented me (fixed here). Also a duplicated code in `traits.d` to handle mixins is removed (it was a copy of `typesem.d:compileTypeMixin` function).
1 parent 0f4d152 commit 3dd9769

File tree

5 files changed

+28
-68
lines changed

5 files changed

+28
-68
lines changed

src/dmd/dsymbol.d

-7
Original file line numberDiff line numberDiff line change
@@ -957,14 +957,7 @@ extern (C++) class Dsymbol : ASTNode
957957
TemplateInstance ti = st.isTemplateInstance();
958958
sm = s.search(loc, ti.name);
959959
if (!sm)
960-
{
961-
sm = s.search_correct(ti.name);
962-
if (sm)
963-
.error(loc, "template identifier `%s` is not a member of %s `%s`, did you mean %s `%s`?", ti.name.toChars(), s.kind(), s.toPrettyChars(), sm.kind(), sm.toChars());
964-
else
965-
.error(loc, "template identifier `%s` is not a member of %s `%s`", ti.name.toChars(), s.kind(), s.toPrettyChars());
966960
return null;
967-
}
968961
sm = sm.toAlias();
969962
TemplateDeclaration td = sm.isTemplateDeclaration();
970963
if (!td)

src/dmd/traits.d

+19-55
Original file line numberDiff line numberDiff line change
@@ -1733,69 +1733,33 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
17331733
bool err = false;
17341734

17351735
auto t = isType(o);
1736-
while (t)
1736+
auto ex = isExpression(o);
1737+
if (t)
17371738
{
1738-
if (auto tm = t.isTypeMixin())
1739+
Dsymbol s;
1740+
t.resolve(e.loc, sc2, ex, t, s);
1741+
if (t)
17391742
{
1740-
/* The mixin string could be a type or an expression.
1741-
* Have to try compiling it to see.
1742-
*/
1743-
OutBuffer buf;
1744-
if (expressionsToString(buf, sc, tm.exps))
1745-
{
1743+
t.typeSemantic(e.loc, sc2);
1744+
if (t.ty == Terror)
17461745
err = true;
1747-
break;
1748-
}
1749-
const olderrors = global.errors;
1750-
const len = buf.length;
1751-
buf.writeByte(0);
1752-
const str = buf.extractSlice()[0 .. len];
1753-
scope p = new Parser!ASTCodegen(e.loc, sc._module, str, false);
1754-
p.nextToken();
1755-
//printf("p.loc.linnum = %d\n", p.loc.linnum);
1756-
1757-
o = p.parseTypeOrAssignExp(TOK.endOfFile);
1758-
if (olderrors != global.errors || p.token.value != TOK.endOfFile)
1759-
{
1760-
err = true;
1761-
break;
1762-
}
1763-
t = o.isType();
17641746
}
1765-
else
1766-
break;
1747+
else if (s && s.errors)
1748+
err = true;
17671749
}
1768-
1769-
if (!err)
1750+
if (ex)
17701751
{
1771-
auto ex = t ? t.typeToExpression() : isExpression(o);
1772-
if (!ex && t)
1752+
ex = ex.expressionSemantic(sc2);
1753+
ex = resolvePropertiesOnly(sc2, ex);
1754+
ex = ex.optimize(WANTvalue);
1755+
if (sc2.func && sc2.func.type.ty == Tfunction)
17731756
{
1774-
Dsymbol s;
1775-
t.resolve(e.loc, sc2, ex, t, s);
1776-
if (t)
1777-
{
1778-
t.typeSemantic(e.loc, sc2);
1779-
if (t.ty == Terror)
1780-
err = true;
1781-
}
1782-
else if (s && s.errors)
1783-
err = true;
1784-
}
1785-
if (ex)
1786-
{
1787-
ex = ex.expressionSemantic(sc2);
1788-
ex = resolvePropertiesOnly(sc2, ex);
1789-
ex = ex.optimize(WANTvalue);
1790-
if (sc2.func && sc2.func.type.ty == Tfunction)
1791-
{
1792-
const tf = cast(TypeFunction)sc2.func.type;
1793-
err |= tf.isnothrow && canThrow(ex, sc2.func, false);
1794-
}
1795-
ex = checkGC(sc2, ex);
1796-
if (ex.op == EXP.error)
1797-
err = true;
1757+
const tf = cast(TypeFunction)sc2.func.type;
1758+
err |= tf.isnothrow && canThrow(ex, sc2.func, false);
17981759
}
1760+
ex = checkGC(sc2, ex);
1761+
if (ex.op == EXP.error)
1762+
err = true;
17991763
}
18001764

18011765
// Carefully detach the scope from the parent and throw it away as

src/dmd/typesem.d

+1-4
Original file line numberDiff line numberDiff line change
@@ -2288,10 +2288,7 @@ RootObject compileTypeMixin(TypeMixin tm, Loc loc, Scope* sc)
22882288
return null;
22892289
}
22902290

2291-
Type t = o.isType();
2292-
Expression e = t ? t.typeToExpression() : o.isExpression();
2293-
2294-
return (!e && t) ? t : e;
2291+
return o;
22952292
}
22962293

22972294

test/compilable/mixintype2.d

+6
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,9 @@ void test_statements_22356()
115115
mixin("int") y22356, z22356;
116116
static assert(is(typeof(y22356) == int) && is(typeof(z22356) == int));
117117
}
118+
119+
/**************************************************/
120+
// https://issues.dlang.org/show_bug.cgi?id=22969
121+
122+
enum e = 0;
123+
alias a = mixin("e");

test/fail_compilation/diag14235.d

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
EXTRA_FILES: imports/a14235.d
33
TEST_OUTPUT:
44
---
5-
fail_compilation/diag14235.d(12): Error: template identifier `Undefined` is not a member of module `imports.a14235`
6-
fail_compilation/diag14235.d(13): Error: template identifier `Something` is not a member of module `imports.a14235`, did you mean struct `SomeThing(T...)`?
5+
fail_compilation/diag14235.d(12): Error: undefined identifier `Undefined` in module `imports.a14235`
6+
fail_compilation/diag14235.d(13): Error: undefined identifier `Something` in module `imports.a14235`, did you mean struct `SomeThing(T...)`?
77
fail_compilation/diag14235.d(14): Error: `imports.a14235.SomeClass` is not a template, it is a class
88
---
99
*/

0 commit comments

Comments
 (0)