Bug 23947 – If a class overloads a method mixing private and public and the last overload is public, the method is always public.

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-05-30T14:33:56Z
Last change time
2023-06-16T11:51:22Z
Keywords
accepts-invalid, industry, pull
Assigned to
No Owner
Creator
FeepingCreature

Comments

Comment #0 by default_357-line — 2023-05-30T14:33:56Z
Consider this code: --- b.d struct X { } struct Y { } class Class { private void handle(X x) { } public void handle(Y y) { } } --- a.d import b; void main() { Class.init.handle(X.init); } It compiles, even though handle(X) is private. It correctly errors if the order of handle() is swapped, and permits calling with Y.init - it only assumes all methods are public if the last method is public. Wow.
Comment #1 by default_357-line — 2023-05-30T14:48:29Z
Correction: more testing suggests that the accepts-invalid condition is "the method is private, but a method defined after it in the overload set is public". Doesn't have to be the last one. Consider: this compiles. --- b.d struct X { } struct Y { } struct Z { } class Class { private void handle(X x) { } public void handle(Y y) { } private void handle(Z z) { } }
Comment #2 by dlang-bot — 2023-05-30T16:05:40Z
@FeepingCreature updated dlang/dmd pull request #15282 "Fix issue 23974: Class method private is ignored if there's a public overload after it" fixing this issue: - Fix issue 23947: If checking access after overload resolution, only check the specific overload selected, not the most public overload of the set. This is a deprecation because making it an error would force issue 21275 to be an error as well. https://github.com/dlang/dmd/pull/15282
Comment #3 by dlang-bot — 2023-06-13T07:20:16Z
dlang/dmd pull request #15282 "Fix issue 23947: Class method private is ignored if there's a public overload after it" was merged into master: - 8feaf5262cf35aa48b26b5177c9c1db2790f341c by Mathis Beer: Fix issue 23947: If checking access after overload resolution, only check the specific overload selected, not the most public overload of the set. This deprecation also covers the deprecation for issue 21275. This is a deprecation because making it an error would force issue 21275 to be an error as well. https://github.com/dlang/dmd/pull/15282
Comment #4 by dlang-bugzilla — 2023-06-14T12:45:57Z
*** Issue 23992 has been marked as a duplicate of this issue. ***
Comment #5 by dlang-bot — 2023-06-16T11:51:22Z
dlang/dmd pull request #15319 "Make 'private function is not accessible' deprecation an error." was merged into master: - fd0ebb96e18d3fa54d53bfb71210da2ff9135463 by Mathis Beer: Make 'private function is not accessible' deprecation an error. Affects issue 21275, 23947. https://github.com/dlang/dmd/pull/15319