From 1f98c6b69854348a271b9cd1314f77822f875f77 Mon Sep 17 00:00:00 2001 From: Ilya Yanok Date: Wed, 23 Oct 2024 14:34:19 +0200 Subject: [PATCH] dsymbolsem/InstMemberWalker: also visit generated structs' members 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. --- compiler/src/dmd/dsymbolsem.d | 9 +++++++ compiler/test/compilable/issue24830.sh | 34 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 compiler/test/compilable/issue24830.sh diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index ec73e08858e..06eae929abc 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -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) ); diff --git a/compiler/test/compilable/issue24830.sh b/compiler/test/compilable/issue24830.sh new file mode 100755 index 00000000000..26864c24493 --- /dev/null +++ b/compiler/test/compilable/issue24830.sh @@ -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 <$D_FILE2 <