Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 22969 - Can't mixin name of manifest constant on right-hand side of alias declaration #13946

Merged
merged 1 commit into from Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/dmd/dsymbol.d
Expand Up @@ -957,14 +957,7 @@ extern (C++) class Dsymbol : ASTNode
TemplateInstance ti = st.isTemplateInstance();
sm = s.search(loc, ti.name);
if (!sm)
{
sm = s.search_correct(ti.name);
if (sm)
.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());
else
.error(loc, "template identifier `%s` is not a member of %s `%s`", ti.name.toChars(), s.kind(), s.toPrettyChars());
return null;
}
sm = sm.toAlias();
TemplateDeclaration td = sm.isTemplateDeclaration();
if (!td)
Expand Down
74 changes: 19 additions & 55 deletions src/dmd/traits.d
Expand Up @@ -1733,69 +1733,33 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
bool err = false;

auto t = isType(o);
while (t)
auto ex = isExpression(o);
if (t)
{
if (auto tm = t.isTypeMixin())
Dsymbol s;
t.resolve(e.loc, sc2, ex, t, s);
if (t)
{
/* The mixin string could be a type or an expression.
* Have to try compiling it to see.
*/
OutBuffer buf;
if (expressionsToString(buf, sc, tm.exps))
{
t.typeSemantic(e.loc, sc2);
if (t.ty == Terror)
err = true;
break;
}
const olderrors = global.errors;
const len = buf.length;
buf.writeByte(0);
const str = buf.extractSlice()[0 .. len];
scope p = new Parser!ASTCodegen(e.loc, sc._module, str, false);
p.nextToken();
//printf("p.loc.linnum = %d\n", p.loc.linnum);

o = p.parseTypeOrAssignExp(TOK.endOfFile);
if (olderrors != global.errors || p.token.value != TOK.endOfFile)
{
err = true;
break;
}
t = o.isType();
}
else
break;
else if (s && s.errors)
err = true;
}

if (!err)
if (ex)
{
auto ex = t ? t.typeToExpression() : isExpression(o);
if (!ex && t)
ex = ex.expressionSemantic(sc2);
ex = resolvePropertiesOnly(sc2, ex);
ex = ex.optimize(WANTvalue);
if (sc2.func && sc2.func.type.ty == Tfunction)
{
Dsymbol s;
t.resolve(e.loc, sc2, ex, t, s);
if (t)
{
t.typeSemantic(e.loc, sc2);
if (t.ty == Terror)
err = true;
}
else if (s && s.errors)
err = true;
}
if (ex)
{
ex = ex.expressionSemantic(sc2);
ex = resolvePropertiesOnly(sc2, ex);
ex = ex.optimize(WANTvalue);
if (sc2.func && sc2.func.type.ty == Tfunction)
{
const tf = cast(TypeFunction)sc2.func.type;
err |= tf.isnothrow && canThrow(ex, sc2.func, false);
}
ex = checkGC(sc2, ex);
if (ex.op == EXP.error)
err = true;
const tf = cast(TypeFunction)sc2.func.type;
err |= tf.isnothrow && canThrow(ex, sc2.func, false);
}
ex = checkGC(sc2, ex);
if (ex.op == EXP.error)
err = true;
}

// Carefully detach the scope from the parent and throw it away as
Expand Down
5 changes: 1 addition & 4 deletions src/dmd/typesem.d
Expand Up @@ -2288,10 +2288,7 @@ RootObject compileTypeMixin(TypeMixin tm, Loc loc, Scope* sc)
return null;
}

Type t = o.isType();
Expression e = t ? t.typeToExpression() : o.isExpression();

return (!e && t) ? t : e;
return o;
}


Expand Down
6 changes: 6 additions & 0 deletions test/compilable/mixintype2.d
Expand Up @@ -115,3 +115,9 @@ void test_statements_22356()
mixin("int") y22356, z22356;
static assert(is(typeof(y22356) == int) && is(typeof(z22356) == int));
}

/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22969

enum e = 0;
alias a = mixin("e");
4 changes: 2 additions & 2 deletions test/fail_compilation/diag14235.d
Expand Up @@ -2,8 +2,8 @@
EXTRA_FILES: imports/a14235.d
TEST_OUTPUT:
---
fail_compilation/diag14235.d(12): Error: template identifier `Undefined` is not a member of module `imports.a14235`
fail_compilation/diag14235.d(13): Error: template identifier `Something` is not a member of module `imports.a14235`, did you mean struct `SomeThing(T...)`?
fail_compilation/diag14235.d(12): Error: undefined identifier `Undefined` in module `imports.a14235`
fail_compilation/diag14235.d(13): Error: undefined identifier `Something` in module `imports.a14235`, did you mean struct `SomeThing(T...)`?
fail_compilation/diag14235.d(14): Error: `imports.a14235.SomeClass` is not a template, it is a class
---
*/
Expand Down