Showing with 39 additions and 0 deletions.
  1. +11 −0 src/dclass.d
  2. +28 −0 test/fail_compilation/fail7903.d
11 changes: 11 additions & 0 deletions src/dclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,17 @@ public:
if (deferred)
deferred.errors = true;
}
// Verify fields of a synchronized class are not public
if (storage_class & STCsynchronized)
foreach (vd; this.fields)
{
if (!vd.isThisDeclaration() &&
!vd.prot().isMoreRestrictiveThan(Prot(PROTpublic)))
{
vd.error("Field members of a synchronized class cannot be %s",
protectionToChars(vd.prot().kind));
}
}
if (deferred && !global.gag)
{
deferred.semantic2(sc);
Expand Down
28 changes: 28 additions & 0 deletions test/fail_compilation/fail7903.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7903.d(21): Error: variable fail7903.F1.x Field members of a synchronized class cannot be public
fail_compilation/fail7903.d(22): Error: variable fail7903.F1.y Field members of a synchronized class cannot be export
fail_compilation/fail7903.d(27): Error: variable fail7903.F2.x Field members of a synchronized class cannot be public
---
*/
synchronized class K1
{
public struct S { }
}

synchronized class K2
{
struct S { }
}

synchronized class F1
{
public int x;
export int y;
}

synchronized class F2
{
int x;
}