Skip to content

Commit ed57e32

Browse files
Check trait constructor for accessibility even if not called at Typer (#17094)
This allows to restrict inheritance of traits even if the constructor is not called, or not called at Typer. Fixes #17089
2 parents da9628f + 391730a commit ed57e32

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
@@ -2512,6 +2512,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25122512
checkSimpleKinded(parent)
25132513
// allow missing type parameters if there are implicit arguments to pass
25142514
// since we can infer type arguments from them
2515+
val constr = psym.primaryConstructor
2516+
if psym.is(Trait) && constr.exists && !cls.isRefinementClass then
2517+
ensureAccessible(constr.termRef, superAccess = true, tree.srcPos)
25152518
else
25162519
checkParentCall(result, cls)
25172520
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)