Fix bugzilla 24764 - ICE when -vcg-ast prints imported invariant (#16917)

Co-authored-by: Dennis Korpel <dennis@sarc.nl>
This commit is contained in:
Dennis 2024-10-03 13:47:19 +02:00 committed by GitHub
parent f420f988ab
commit e0259d92e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 3 deletions

View file

@ -1858,9 +1858,9 @@ void toCBuffer(Dsymbol s, ref OutBuffer buf, ref HdrGenState hgs)
if (stcToBuffer(buf, d.storage_class))
buf.writeByte(' ');
buf.writestring("invariant");
if(auto es = d.fbody.isExpStatement())
auto es = d.fbody.isExpStatement();
if (es && es.exp && es.exp.op == EXP.assert_)
{
assert(es.exp && es.exp.op == EXP.assert_);
buf.writestring(" (");
(cast(AssertExp)es.exp).e1.expressionToBuffer(buf, hgs);
buf.writestring(");");

View file

@ -100,6 +100,12 @@ void main()
values();
return 0;
}
import imports.vcg_ast_import;
template imported()
{
import imported = imports.vcg_ast_import;
}
alias myImport = vcg_ast_import;
R!int
{
struct _R
@ -126,6 +132,21 @@ mixin _d_cmain!();
}
}
}
imported!()
{
import object;
struct O
{
invariant
{
}
invariant
{
__invariant0();
}
}
}
RTInfo!(C)
{
enum immutable(void)* RTInfo = null;
@ -150,4 +171,3 @@ RTInfo!(_R)
enum immutable(void)* RTInfo = null;
}

View file

@ -0,0 +1,4 @@
struct O
{
invariant() {}
}

View file

@ -2,6 +2,7 @@
REQUIRED_ARGS: -vcg-ast -o-
PERMUTE_ARGS:
OUTPUT_FILES: compilable/vcg-ast.d.cg
EXTRA_FILES: imports/vcg_ast_import.d
TEST_OUTPUT_FILE: extra-files/vcg-ast.d.cg
*/
@ -63,3 +64,14 @@ void main()
{
values!wchar_t;
}
// https://issues.dlang.org/show_bug.cgi?id=24764
import imports.vcg_ast_import;
template imported()
{
import imported = imports.vcg_ast_import;
}
alias myImport = imported!();