Skip to content

Commit 37e4fe7

Browse files
committed
Check trait constructor for accessibility even if not called at Typer
This allows to restrict inheritance of traits even if the constructor is not called, or not called at Typer. Fixes #17089
1 parent 89a744f commit 37e4fe7

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25112511
checkSimpleKinded(parent)
25122512
// allow missing type parameters if there are implicit arguments to pass
25132513
// since we can infer type arguments from them
2514+
val constr = psym.primaryConstructor
2515+
if constr.exists then
2516+
ensureAccessible(constr.termRef, superAccess = true, tree.srcPos)
25142517
else
25152518
checkParentCall(result, cls)
25162519
if cls is Case then

tests/neg/i17089.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object o:
2+
trait T private[o]()
3+
4+
def test = new o.T { } // error

0 commit comments

Comments
 (0)