Skip to content

Commit

Permalink
dsymbolsem/InstMemberWalker: also visit generated structs' members
Browse files Browse the repository at this point in the history
While updating children's `minst` only going over `members` is not
enough: structs may also have generated methods that are not in
`members`.

As a result, if a generated method instantiates a template, it gets a
poentially wrong `minst`, so can be omitted from the compilation result.

Fixes Bugzilla Issue 24830.
  • Loading branch information
yanok committed Oct 23, 2024
1 parent adb1c3f commit 1f98c6b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4715,6 +4715,15 @@ void templateInstanceSemantic(TemplateInstance tempinst, Scope* sc, ArgumentList
visit(cast(Dsymbol)sds);
}

override void visit(StructDeclaration sd)
{
// need to visit auto-generated methods as well
if (sd.xeq) visit(sd.xeq);
if (sd.xcmp) visit(sd.xcmp);
if (sd.xhash) visit(sd.xhash);
visit(cast(ScopeDsymbol)sd);
}

override void visit(AttribDeclaration ad)
{
ad.include(null).foreachDsymbol( s => s.accept(this) );
Expand Down
34 changes: 34 additions & 0 deletions compiler/test/compilable/issue24830.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /usr/bin/env bash

TEST_DIR=${OUTPUT_BASE}
# create two modules each depending on each other.
# They both do the same template instantiation.
D_FILE1=$TEST_DIR/first.d
D_FILE2=$TEST_DIR/second.d
D_OBJ1=$TEST_DIR/first${OBJ}
D_OBJ2=$TEST_DIR/second${OBJ}
APP=$TEST_DIR/app

mkdir -p $TEST_DIR

cat >$D_FILE1 <<EOF
module first;
import second;
struct S(T) {
int opCmp()(const(S) rhs) const { return 0; }
}
S!int f;
EOF

cat >$D_FILE2 <<EOF
module second;
import first;
S!int s;
EOF

${DMD} -m${MODEL} -c -of${D_OBJ1} -I${TEST_DIR} ${D_FILE1}
${DMD} -m${MODEL} -c -of${D_OBJ2} -I${TEST_DIR} ${D_FILE2}

# Try to link them
${DMD} -main -m${MODEL} -of${APP} ${D_OBJ1} ${D_OBJ2}

0 comments on commit 1f98c6b

Please sign in to comment.