Skip to content

Commit fe6c10f

Browse files
committed
Propagate notNullinfo in ReTyper
the case of `typedTyped` was missing. This allows to use a plain inline `assert` in DottyPredef.
1 parent 9c4f6f2 commit fe6c10f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ast.{tpd, untpd, Trees}
1212
import Trees._
1313
import scala.util.control.NonFatal
1414
import util.Spans.Span
15+
import Nullables._
1516

1617
/** A version of Typer that keeps all symbols defined and referenced in a
1718
* previously typed tree.
@@ -53,13 +54,15 @@ class ReTyper extends Typer with ReChecking {
5354

5455
override def typedTyped(tree: untpd.Typed, pt: Type)(using Context): Tree = {
5556
assertTyped(tree)
57+
5658
val tpt1 = checkSimpleKinded(typedType(tree.tpt))
5759
val expr1 = tree.expr match {
5860
case id: untpd.Ident if (ctx.mode is Mode.Pattern) && untpd.isVarPattern(id) && (id.name == nme.WILDCARD || id.name == nme.WILDCARD_STAR) =>
5961
tree.expr.withType(tpt1.tpe)
6062
case _ => typed(tree.expr)
6163
}
62-
untpd.cpy.Typed(tree)(expr1, tpt1).withType(tree.typeOpt)
64+
val result = untpd.cpy.Typed(tree)(expr1, tpt1).withType(tree.typeOpt)
65+
if ctx.mode.isExpr then result.withNotNullInfo(expr1.notNullInfo) else result
6366
}
6467

6568
override def typedTypeTree(tree: untpd.TypeTree, pt: Type)(using Context): TypeTree =

library/src/dotty/DottyPredef.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ package dotty
33
object DottyPredef {
44
import compiletime.summonFrom
55

6-
inline final def assert(inline assertion: Boolean, inline message: => Any): Unit = {
7-
if (!assertion)
8-
scala.runtime.Scala3RunTime.assertFailed(message)
9-
}
6+
inline def assert(inline assertion: Boolean, inline message: => Any): Unit =
7+
if !assertion then scala.runtime.Scala3RunTime.assertFailed(message)
108

11-
transparent inline final def assert(inline assertion: Boolean): Unit = {
12-
if (!assertion)
13-
scala.runtime.Scala3RunTime.assertFailed()
14-
}
9+
inline def assert(inline assertion: Boolean): Unit =
10+
if !assertion then scala.runtime.Scala3RunTime.assertFailed()
1511

1612
/**
1713
* Retrieve the single value of a type with a unique inhabitant.

0 commit comments

Comments
 (0)