Fix Bugzilla 24705 - Arguments of synchronized method are wrongly shared with -preview=nosharedaccess

This commit is contained in:
Nick Treleaven 2024-08-16 15:45:36 +01:00 committed by The Dlang Bot
parent ae2dc11619
commit 1d2e15ef18
2 changed files with 8 additions and 3 deletions

View file

@ -15155,10 +15155,8 @@ bool checkSharedAccess(Expression e, Scope* sc, bool returnRef = false)
{ {
if (e.var.isThisDeclaration()) if (e.var.isThisDeclaration())
return false; return false;
else
return sharedError(e);
} }
else if (!allowRef && e.var.type.isShared()) if (!allowRef && e.var.type.isShared())
return sharedError(e); return sharedError(e);
return false; return false;

View file

@ -20,4 +20,11 @@ class Oops
// this shouldn't compile `k` is a field of class `Oops` // this shouldn't compile `k` is a field of class `Oops`
static assert (!__traits(compiles, k = 2)); static assert (!__traits(compiles, k = 2));
} }
// https://issues.dlang.org/show_bug.cgi?id=24705
synchronized void foo(int n)
{
// Error: direct access to shared `n` is not allowed, see `core.atomic`
int a = n;
}
} }