Skip to content

Commit

Permalink
Remove cast(STC) from TypeTag.semantic (#20931)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Feb 28, 2025
1 parent 2c304a4 commit 978b108
Showing 1 changed file with 12 additions and 6 deletions.
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

0 comments on commit 978b108

Please sign in to comment.