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

Remove cast(STC) from TypeTag.semantic #20931

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2985,16 +2985,22 @@ Type typeSemantic(Type type, Loc loc, Scope* sc)
Type visitTag(TypeTag mtype)
{
//printf("TypeTag.semantic() %s\n", mtype.toChars());
Type returnType(Type t)
{
Type returnType(TypeTag tt)
{
Type t = tt.resolved;
// To make const checking work, the const STC needs to be added:
// t = t.resolved.addSTC(mtype.mod.ModToStc);
// However, this currently fails compilable/test22875.i
// Apparently there's some aliasing going on, where mutable
// versions of the type also get const applied to them.
return t.deco ? t : t.merge();
}

if (mtype.resolved)
{
/* struct S s, *p;
*/
return returnType(mtype.resolved.addSTC(cast(STC) mtype.mod));
return returnType(mtype);
}

/* Find the current scope by skipping tag scopes.
Expand Down Expand Up @@ -3067,7 +3073,7 @@ Type typeSemantic(Type type, Loc loc, Scope* sc)
{
mtype.id = Identifier.generateId("__tag"[]);
declareTag();
return returnType(mtype.resolved.addSTC(cast(STC) mtype.mod));
return returnType(mtype);
}

/* look for pre-existing declaration
Expand All @@ -3080,7 +3086,7 @@ Type typeSemantic(Type type, Loc loc, Scope* sc)
if (mtype.tok == TOK.enum_ && !mtype.members)
.error(mtype.loc, "`enum %s` is incomplete without members", mtype.id.toChars()); // C11 6.7.2.3-3
declareTag();
return returnType(mtype.resolved.addSTC(cast(STC) mtype.mod));
return returnType(mtype);
}

/* A redeclaration only happens if both declarations are in
Expand Down Expand Up @@ -3180,7 +3186,7 @@ Type typeSemantic(Type type, Loc loc, Scope* sc)
declareTag();
}
}
return returnType(mtype.resolved.addSTC(cast(STC) mtype.mod));
return returnType(mtype);
}

switch (type.ty)
Expand Down
Loading