Issue 24387 - Base class construction ignores private
Summary: Base class construction ignores private
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2024-02-11 16:30 UTC by Paul Backus
Modified: 2024-02-13 12:21 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Paul Backus 2024-02-11 16:30:55 UTC
As of DMD 2.107.0, the following program compiles without errors:

--- lib.d
module lib;

class Base
{
    private this(int n) {}
}
--- app.d
module app;

import lib;

class Derived : Base
{
    this() { super(42); }
}
---

According to the language spec [1], private symbols can only be accessed from within the module that defines them. The section on base class construction [2] does not mention any exception to that rule. Therefore, if the spec is correct, the super(42) call should not compile.

[1] https://dlang.org/spec/attribute.html#private
[2] https://dlang.org/spec/class.html#base-construction
Comment 1 Dlang Bot 2024-02-12 11:59:25 UTC
@ntrel created dlang/dmd pull request #16180 "Fix Bugzilla 24387 - Base class construction ignores private" fixing this issue:

- Fix Bugzilla 24387 - Base class construction ignores private

https://github.com/dlang/dmd/pull/16180
Comment 2 Dlang Bot 2024-02-13 12:21:54 UTC
dlang/dmd pull request #16180 "Fix Bugzilla 24387 - Base class construction ignores private" was merged into master:

- 0dbefb21cb0edd86b668bac38c8680f7bedb3791 by Nick Treleaven:
  Fix Bugzilla 24387 - Base class construction ignores private

https://github.com/dlang/dmd/pull/16180