diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index f4487e2bfa5e..d033f2230a46 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -795,6 +795,15 @@ trait Namers extends MethodSynthesis { tree.symbol = enterClassSymbol(tree) tree.symbol setInfo completerOf(tree) + // ensure completion before patmat (unit is not run for java, so add check directly to phase) + if (tree.symbol.isJava) { + val sym = tree.symbol + currentRun.typerPhase match { + case ph: typerFactory.TyperPhase => ph.addCheckAfterTyper(() => sym.initialize) + case _ => + } + } + if (mods.isCase) { val m = ensureCompanionObject(tree, caseModuleDef) m.moduleClass.updateAttachment(new ClassForCaseCompanionAttachment(tree)) diff --git a/test/files/neg/t12159d.check b/test/files/neg/t12159d.check index bda2e48622ce..5ee9d95e10a4 100644 --- a/test/files/neg/t12159d.check +++ b/test/files/neg/t12159d.check @@ -1,7 +1,7 @@ -s.scala:5: error: illegal inheritance from sealed class H -class S extends H { - ^ -s.scala:8: error: illegal inheritance from sealed trait I -trait T extends I { - ^ -2 errors +t_3.scala:7: warning: match may not be exhaustive. +It would fail on the following input: W() + x match { + ^ +error: No warnings can be incurred under -Werror. +1 warning +1 error diff --git a/test/files/neg/t12159d/X_3.java b/test/files/neg/t12159d/X_3.java new file mode 100644 index 000000000000..e47fd05a3f08 --- /dev/null +++ b/test/files/neg/t12159d/X_3.java @@ -0,0 +1,14 @@ +// javaVersion: 17+ +package p; + +sealed abstract public class X_3 { +} + +final class W extends X_3 { +} + +final class Y extends X_3 { +} + +final class Z extends X_3 { +} diff --git a/test/files/neg/t12159d/t_3.scala b/test/files/neg/t12159d/t_3.scala new file mode 100644 index 000000000000..78417346357a --- /dev/null +++ b/test/files/neg/t12159d/t_3.scala @@ -0,0 +1,12 @@ +// javaVersion: 17+ +// scalac: -Werror +package p + +class C { + def f(x: X_3) = + x match { + case y: Y => y.toString + case z: Z => z.toString + } +} +