Skip to content

Commit

Permalink
Exhaustive check in mixed compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt authored and lrytz committed Mar 29, 2023
1 parent ced92ac commit 8751aeb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/compiler/scala/tools/nsc/typechecker/Namers.scala
Expand Up @@ -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))
Expand Down
14 changes: 7 additions & 7 deletions 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
14 changes: 14 additions & 0 deletions 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 {
}
12 changes: 12 additions & 0 deletions 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
}
}

0 comments on commit 8751aeb

Please sign in to comment.