Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 18 additions & 9 deletions compiler/src/dmd/semantic3.d
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,10 @@ private extern(C++) final class Semantic3Visitor : Visitor

override void visit(TypeInfoAssociativeArrayDeclaration ti)
{
if (ti.semanticRun >= PASS.semantic3)
return;
ti.semanticRun = PASS.semantic3;

auto t = ti.tinfo.isTypeAArray();
Loc loc = t.loc;
auto sc2 = sc ? sc : ti._scope;
Expand Down Expand Up @@ -1643,19 +1647,24 @@ private extern(C++) final class Semantic3Visitor : Visitor
// generate ti.xtoHash
auto hashinst = makeDotExp(Identifier.idPool("aaGetHash"));
e = expressionSemantic(hashinst, sc2);
assert(e.isVarExp() && e.type.isTypeFunction());
ti.xtoHash = e.isVarExp().var;
if (auto tmpl = ti.xtoHash.parent.isTemplateInstance())
tmpl.minst = sc2._module.importedFrom; // ensure it gets emitted
if (!e.isErrorExp())
{
assert(e.isVarExp() && e.type.isTypeFunction());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just realised that this will still trigger an assert and ICE if druntime is seriously mismatched with the compiler by declaring these fields but of a different type.

class TypeInfo_AssociativeArray
{
    alias aaOpEqual(K, V) = () => false;
    alias aaGetHash(K, V) = () => 0;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ti.xtoHash = e.isVarExp().var;
if (auto tmpl = ti.xtoHash.parent.isTemplateInstance())
tmpl.minst = sc2._module.importedFrom; // ensure it gets emitted
}

// generate ti.xopEqual
auto equalinst = makeDotExp(Identifier.idPool("aaOpEqual"));
e = expressionSemantic(equalinst, sc2);
assert(e.isVarExp() && e.type.isTypeFunction());
ti.xopEqual = e.isVarExp().var;
if (auto tmpl = ti.xopEqual.parent.isTemplateInstance())
tmpl.minst = sc2._module.importedFrom; // ensure it gets emitted

if (!e.isErrorExp())
{
assert(e.isVarExp() && e.type.isTypeFunction());
ti.xopEqual = e.isVarExp().var;
if (auto tmpl = ti.xopEqual.parent.isTemplateInstance())
tmpl.minst = sc2._module.importedFrom; // ensure it gets emitted
}
visit(cast(ASTCodegen.TypeInfoDeclaration)ti);
}
}
Expand Down
23 changes: 23 additions & 0 deletions compiler/test/fail_compilation/test20863.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// must not assert/crash with empty declarations
/* TEST_OUTPUT:
---
fail_compilation\test20863.d(21): Error: no property `Entry` for type `object.TypeInfo_AssociativeArray`
fail_compilation\test20863.d(17): class `TypeInfo_AssociativeArray` defined here
fail_compilation\test20863.d(21): Error: no property `aaGetHash` for type `object.TypeInfo_AssociativeArray`
fail_compilation\test20863.d(17): class `TypeInfo_AssociativeArray` defined here
fail_compilation\test20863.d(21): Error: no property `aaOpEqual` for type `object.TypeInfo_AssociativeArray`
fail_compilation\test20863.d(17): class `TypeInfo_AssociativeArray` defined here
---
*/

module object;

class Object { }
class TypeInfo { }
class TypeInfo_AssociativeArray { }

extern(C) int main()
{
int[int] aa;
return 0;
}
Loading