Skip to content

Commit

Permalink
Fix Issue 7903 - Disallow public members in a synchronized class
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrejMitrovic committed Oct 11, 2015
1 parent d2c607f commit 1ac5c08
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/dclass.d
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
@@ -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;
}

0 comments on commit 1ac5c08

Please sign in to comment.