Skip to content

Commit e459349

Browse files
committed
Only strip ascriptions that do not break subtyping
1 parent bea6e24 commit e459349

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 8e4a40588491608aa40099f79c881d54a5094e75

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,11 +1047,18 @@ class Inliner(val call: tpd.Tree)(using Context):
10471047
reduceInlineMatchExpr(sel)
10481048
}
10491049

1050+
private def shouldStripAscription(tree: Typed)(using Context): Boolean =
1051+
val exprTp = tree.expr.tpe
1052+
tree.hasAttachment(PrepareInlineable.InlineResultAscription)
1053+
&& exprTp.exists
1054+
&& !exprTp.widen.isRef(defn.NothingClass)
1055+
&& !exprTp.widen.isRef(defn.NullClass)
1056+
&& (exprTp frozen_<:< tree.tpe)
1057+
10501058
override def typedTyped(tree: untpd.Typed, pt: Type)(using Context): Tree =
1051-
if tree.hasAttachment(PrepareInlineable.InlineResultAscription) then
1052-
typedExpr(tree.expr, pt)
1053-
else
1054-
super.typedTyped(tree, pt)
1059+
super.typedTyped(tree, pt) match
1060+
case typedTree: Typed if shouldStripAscription(typedTree) => typedTree.expr
1061+
case typedTree => typedTree
10551062

10561063
override def newLikeThis(nestingLevel: Int): Typer = new InlineTyper(initialErrorCount, nestingLevel)
10571064

0 commit comments

Comments
 (0)