Fix Bugzilla 24387 - Base class construction ignores private (#16180)

* Fix Bugzilla 24387 - Base class construction ignores private

* Fix access checks for ctor overloads
This commit is contained in:
Nick Treleaven 2024-02-13 12:21:47 +00:00 committed by GitHub
parent e367663549
commit 39dffd8e5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 3 deletions

View file

@ -5023,7 +5023,12 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return setError();
checkFunctionAttributes(exp, sc, f);
checkAccess(cd, exp.loc, sc, f);
if (!checkSymbolAccess(sc, f))
{
error(exp.loc, "%s `%s` is not accessible from module `%s`",
f.kind(), f.toPrettyChars(), sc._module.toChars);
return setError();
}
TypeFunction tf = f.type.isTypeFunction();
if (!exp.arguments)
@ -6463,7 +6468,12 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return setError();
checkFunctionAttributes(exp, sc, exp.f);
checkAccess(exp.loc, sc, null, exp.f);
if (!checkSymbolAccess(sc, exp.f))
{
error(exp.loc, "%s `%s` is not accessible from module `%s`",
exp.f.kind(), exp.f.toPrettyChars(), sc._module.toChars);
return setError();
}
exp.e1 = new DotVarExp(exp.e1.loc, exp.e1, exp.f, false);
exp.e1 = exp.e1.expressionSemantic(sc);

View file

@ -3,4 +3,5 @@ module issue21685;
class E
{
private this() {}
public this(int) {}
}

View file

@ -1,7 +1,8 @@
/* REQUIRED_ARGS: -preview=dip1000 -Ifail_compilation/imports
TEST_OUTPUT:
---
fail_compilation/issue21685_main.d(11): Error: class `issue21685.E` constructor `this` is not accessible
fail_compilation/issue21685_main.d(12): Error: constructor `issue21685.E.this` is not accessible from module `issue21685_main`
fail_compilation/issue21685_main.d(19): Error: constructor `issue21685.E.this` is not accessible from module `issue21685_main`
---
*/
import issue21685;
@ -10,3 +11,11 @@ void main()
{
new E;
}
class F : E
{
this()
{
super();
}
}