Commit 05c0b52
committed
Fix protected constructor access checks in secondary constructors and super call arguments
Refine isConstructorAccessOK to check isPrimaryConstructor instead of
isConstructor. This rejects `new Parent(x)` in secondary constructors,
which was incorrectly allowed because ctx.owner.isConstructor was true
for both primary (super call) and secondary constructors.
Add a post-hoc check in checkParentCall that walks super call arguments
and rejects protected constructor accesses within them. This handles
cases like `extends B(new A(1))` where A has a protected constructor
and is a direct or transitive parent. The check leverages the fact that
ctx.owner is the class (not the constructor) in checkParentCall, so
isConstructorAccessOK is naturally false.1 parent 230925d commit 05c0b52
File tree
3 files changed
+25
-1
lines changed- compiler/src/dotty/tools/dotc
- core
- typer
- tests/neg/i25442
3 files changed
+25
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
947 | 947 | | |
948 | 948 | | |
949 | 949 | | |
950 | | - | |
| 950 | + | |
951 | 951 | | |
952 | 952 | | |
953 | 953 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1415 | 1415 | | |
1416 | 1416 | | |
1417 | 1417 | | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
1418 | 1441 | | |
1419 | 1442 | | |
1420 | 1443 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
0 commit comments