From 1ac5c08bb374496bfbc175d495c1307a98008238 Mon Sep 17 00:00:00 2001 From: Andrej Mitrovic Date: Sun, 11 Oct 2015 20:46:27 +0200 Subject: [PATCH] Fix Issue 7903 - Disallow public members in a synchronized class --- src/dclass.d | 11 +++++++++++ test/fail_compilation/fail7903.d | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/fail_compilation/fail7903.d diff --git a/src/dclass.d b/src/dclass.d index d917db38a82c..3bb6c6033bf7 100644 --- a/src/dclass.d +++ b/src/dclass.d @@ -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); diff --git a/test/fail_compilation/fail7903.d b/test/fail_compilation/fail7903.d new file mode 100644 index 000000000000..7759f1ada178 --- /dev/null +++ b/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; +}