Skip to content
Closed
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
18 changes: 17 additions & 1 deletion compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -5073,6 +5073,22 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
return isCCompatible(ats.sym, bts.sym);
}

// Treat arrays of anonymous structs/unions as compatible when element types match.
static bool isCCompatibleType(Type a, Type b)
{
if (a.equals(b))
return true;

if (TypeSArray asa = a.isTypeSArray())
{
TypeSArray bsa = b.isTypeSArray();
if (bsa && asa.dim && bsa.dim && asa.dim.toInteger() == bsa.dim.toInteger())
return isCCompatibleType(asa.nextOf(), bsa.nextOf());
}

return isCCompatibleUnnamedStruct(a, b);
}

if (a.fields.length != b.fields.length)
{
incompatError();
Expand Down Expand Up @@ -5129,7 +5145,7 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
// their members such that each pair of corresponding
// members are declared with compatible types;
//
if (!a_field.type.equals(b_field.type) && !isCCompatibleUnnamedStruct(a_field.type, b_field.type))
if (!isCCompatibleType(a_field.type, b_field.type))
{
// Already errored, just bail
incompatError();
Expand Down
8 changes: 8 additions & 0 deletions compiler/test/compilable/imports/imp23072.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
typedef struct _SCOPE_TABLE_AMD64 {
struct { int x; } ScopeRecord[1];
} _SCOPE_TABLE_AMD64;

typedef struct _SCOPE_TABLE_UNION {
union { int a; float b; } U[2];
struct { int y; } Nested[2][3];
} _SCOPE_TABLE_UNION;
1 change: 1 addition & 0 deletions compiler/test/compilable/imports/imp23072a.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "imp23072.h"
1 change: 1 addition & 0 deletions compiler/test/compilable/imports/imp23072b.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "imp23072.h"
7 changes: 7 additions & 0 deletions compiler/test/compilable/test23072.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module compiler.test.compilable.test23072;

// https://github.com/dlang/dmd/issues/23072
// EXTRA_FILES: imports/imp23072a.c imports/imp23072b.c imports/imp23072.h

import imports.imp23072a;
import imports.imp23072b;
Loading