Skip to content

Commit 957a80f

Browse files
Merge pull request #8187 from dotty-staging/fix-#8186
Fix #8186: Check trait secondary constructors
2 parents 86d5d69 + 864f81d commit 957a80f

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, butNot = JavaDefined))
444+
fail("Traits cannot have secondary constructors " + sym.owner.flagsString)
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)