Skip to content

Commit a691e96

Browse files
committed
Recompute nullability info when inlining
1 parent 1910c87 commit a691e96

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import ErrorReporting.errorTree
2424
import dotty.tools.dotc.tastyreflect.ReflectionImpl
2525
import dotty.tools.dotc.util.{SimpleIdentityMap, SimpleIdentitySet, SourceFile, SourcePosition}
2626
import dotty.tools.dotc.parsing.Parsers.Parser
27+
import Nullables.given
2728

2829
import collection.mutable
2930
import reporting.trace
@@ -1064,10 +1065,18 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
10641065
errorTree(tree, em"""cannot reduce inline if
10651066
| its condition ${tree.cond}
10661067
| is not a constant value""")
1067-
else {
1068+
else
1069+
// Recompute nullablity info. This is needed because inlined code could have come
1070+
// from Tasty where no nullability info is kept.
1071+
val addNullable = new TreeTraverser {
1072+
def traverse(tree: Tree)(implicit ctx: Context) =
1073+
traverseChildren(tree)
1074+
tree.computeNullable
1075+
}
1076+
addNullable.traverse(cond1)
1077+
10681078
val if1 = untpd.cpy.If(tree)(cond = untpd.TypedSplice(cond1))
10691079
super.typedIf(if1, pt)
1070-
}
10711080
}
10721081

10731082
override def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree =

0 commit comments

Comments
 (0)