Skip to content

Commit a80a11e

Browse files
committed
Fix #8186: Check trait secondary constructors
1 parent c48a598 commit a80a11e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ object Checking {
440440
}
441441
if (sym.isValueClass && sym.is(Trait) && !sym.isRefinementClass)
442442
fail(CannotExtendAnyVal(sym))
443+
if (sym.isConstructor && !sym.isPrimaryConstructor && sym.owner.is(Trait))
444+
fail("Traits cannot have secondary constructors")
443445
checkCombination(Final, Open)
444446
checkCombination(Sealed, Open)
445447
checkCombination(Final, Sealed)

tests/neg/i8186.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Test1() {
2+
def this(x: Int) = // error
3+
this()
4+
}
5+
6+
trait Test2(x: Int) {
7+
def this() = // error
8+
this(3)
9+
}

0 commit comments

Comments
 (0)