diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 74db0593cfc5..f3f7e511966f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -440,6 +440,8 @@ object Checking { } if (sym.isValueClass && sym.is(Trait) && !sym.isRefinementClass) fail(CannotExtendAnyVal(sym)) + if (sym.isConstructor && !sym.isPrimaryConstructor && sym.owner.is(Trait, butNot = JavaDefined)) + fail("Traits cannot have secondary constructors " + sym.owner.flagsString) checkCombination(Final, Open) checkCombination(Sealed, Open) checkCombination(Final, Sealed) diff --git a/tests/neg/i8186.scala b/tests/neg/i8186.scala new file mode 100644 index 000000000000..4e1cf925e6c4 --- /dev/null +++ b/tests/neg/i8186.scala @@ -0,0 +1,9 @@ +trait Test1() { + def this(x: Int) = // error + this() +} + +trait Test2(x: Int) { + def this() = // error + this(3) +}