@@ -18,6 +18,7 @@ import dotty.tools.dotc.transform.MegaPhase.MiniPhase
1818import parsing .Parsers .Parser
1919import transform .{PostTyper , Inlining , CrossVersionChecks }
2020import staging .StagingLevel
21+ import cc .CleanupRetains
2122
2223import collection .mutable
2324import reporting .{NotConstant , trace }
@@ -100,18 +101,33 @@ object Inlines:
100101 * and body that replace it.
101102 */
102103 def inlineCall (tree : Tree )(using Context ): Tree = ctx.profiler.onInlineCall(tree.symbol):
103- if tree.symbol.denot != SymDenotations .NoDenotation
104- && tree.symbol.effectiveOwner == defn.CompiletimeTestingPackage .moduleClass
104+
105+ /** Strip @retains annotations from inferred types in the call tree */
106+ val stripRetains = CleanupRetains ()
107+ val stripper = new TreeTypeMap (
108+ treeMap = {
109+ case tree : InferredTypeTree =>
110+ val stripped = stripRetains(tree.tpe)
111+ if stripped ne tree.tpe then tree.withType(stripped)
112+ else tree
113+ case tree => tree
114+ }
115+ )
116+
117+ val tree0 = stripper.transform(tree)
118+
119+ if tree0.symbol.denot.exists
120+ && tree0.symbol.effectiveOwner == defn.CompiletimeTestingPackage .moduleClass
105121 then
106- if (tree .symbol == defn.CompiletimeTesting_typeChecks ) return Intrinsics .typeChecks(tree )
107- if (tree .symbol == defn.CompiletimeTesting_typeCheckErrors ) return Intrinsics .typeCheckErrors(tree )
122+ if (tree0 .symbol == defn.CompiletimeTesting_typeChecks ) return Intrinsics .typeChecks(tree0 )
123+ if (tree0 .symbol == defn.CompiletimeTesting_typeCheckErrors ) return Intrinsics .typeCheckErrors(tree0 )
108124
109125 if ctx.isAfterTyper then
110126 // During typer we wait with cross version checks until PostTyper, in order
111127 // not to provoke cyclic references. See i16116 for a test case.
112- CrossVersionChecks .checkRef(tree .symbol, tree .srcPos)
128+ CrossVersionChecks .checkRef(tree0 .symbol, tree0 .srcPos)
113129
114- if tree .symbol.isConstructor then return tree // error already reported for the inline constructor definition
130+ if tree0 .symbol.isConstructor then return tree // error already reported for the inline constructor definition
115131
116132 /** Set the position of all trees logically contained in the expansion of
117133 * inlined call `call` to the position of `call`. This transform is necessary
@@ -159,17 +175,17 @@ object Inlines:
159175 tree
160176 }
161177
162- // assertAllPositioned(tree ) // debug
163- val tree1 = liftBindings(tree , identity)
178+ // assertAllPositioned(tree0 ) // debug
179+ val tree1 = liftBindings(tree0 , identity)
164180 val tree2 =
165181 if bindings.nonEmpty then
166- cpy.Block (tree )(bindings.toList, inlineCall(tree1))
182+ cpy.Block (tree0 )(bindings.toList, inlineCall(tree1))
167183 else if enclosingInlineds.length < ctx.settings.XmaxInlines .value && ! reachedInlinedTreesLimit then
168184 val body =
169- try bodyToInline(tree .symbol) // can typecheck the tree and thereby produce errors
185+ try bodyToInline(tree0 .symbol) // can typecheck the tree and thereby produce errors
170186 catch case _ : MissingInlineInfo =>
171187 throw CyclicReference (ctx.owner)
172- new InlineCall (tree ).expand(body)
188+ new InlineCall (tree0 ).expand(body)
173189 else
174190 ctx.base.stopInlining = true
175191 val (reason, setting) =
0 commit comments