Bug 24735 – Enum is not work within the member function in the synchronized class

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2024-08-31T04:51:39Z
Last change time
2024-08-31T15:14:18Z
Assigned to
No Owner
Creator
Haruki Shigemori

Comments

Comment #0 by rayerd.wiz — 2024-08-31T04:51:39Z
enum { ENUM1 = 1 } enum ENUM2 = 2; synchronized class A { void f() { auto a = ENUM1; // NG, but ENUM1 is constant. auto b = ENUM2; // OK } static void g() { auto c = ENUM1; // OK auto d = ENUM2; // OK } } void main() { A a = new A; a.f(); A.g(); } source\text.d(14,12): Error: direct access to shared `ENUM1` is not allowed, see `core.atomic` source\text.d(27,5): Error: `shared` method `text.A.f` is not callable using a non-shared object
Comment #1 by nick — 2024-08-31T11:46:46Z
> source\text.d(14,12): Error: direct access to shared `ENUM1` is not allowed, see `core.atomic` With -preview=nosharedaccess. Fixed by https://github.com/dlang/dmd/pull/16788 > source\text.d(27,5): Error: `shared` method `text.A.f` is not callable using a non-shared object I think that's intentional.
Comment #2 by rayerd.wiz — 2024-08-31T11:55:40Z
enum { ENUM1 = 1 } enum ENUM2 = 2; synchronized class A { void f() { auto a = ENUM1; // NG, but ENUM1 is constant. auto b = ENUM2; // OK } } void main() { auto a = new shared(A); a.f(); } source\text.d(12,12): Error: direct access to shared `ENUM1` is not allowed, see `core.atomic` Why is ENUM1 shared and ENUM2 not shared?
Comment #3 by nick — 2024-08-31T12:38:51Z
Comment 2 compiles without error with -preview=nosharedaccess and dmd git master.
Comment #4 by rayerd.wiz — 2024-08-31T15:14:18Z
Sorry! I forgot to set the -preview=all option.