@@ -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,34 @@ 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+ typeMap = stripRetains,
109+ treeMap = {
110+ case tree : InferredTypeTree =>
111+ val stripped = stripRetains(tree.tpe)
112+ if stripped ne tree.tpe then tree.withType(stripped)
113+ else tree
114+ case tree => tree
115+ }
116+ )
117+
118+ val tree0 = stripper.transform(tree)
119+
120+ if tree0.symbol.denot != SymDenotations .NoDenotation
121+ && tree0.symbol.effectiveOwner == defn.CompiletimeTestingPackage .moduleClass
105122 then
106- if (tree .symbol == defn.CompiletimeTesting_typeChecks ) return Intrinsics .typeChecks(tree )
107- if (tree .symbol == defn.CompiletimeTesting_typeCheckErrors ) return Intrinsics .typeCheckErrors(tree )
123+ if (tree0 .symbol == defn.CompiletimeTesting_typeChecks ) return Intrinsics .typeChecks(tree0 )
124+ if (tree0 .symbol == defn.CompiletimeTesting_typeCheckErrors ) return Intrinsics .typeCheckErrors(tree0 )
108125
109126 if ctx.isAfterTyper then
110127 // During typer we wait with cross version checks until PostTyper, in order
111128 // not to provoke cyclic references. See i16116 for a test case.
112- CrossVersionChecks .checkRef(tree .symbol, tree .srcPos)
129+ CrossVersionChecks .checkRef(tree0 .symbol, tree0 .srcPos)
113130
114- if tree .symbol.isConstructor then return tree // error already reported for the inline constructor definition
131+ if tree0 .symbol.isConstructor then return tree // error already reported for the inline constructor definition
115132
116133 /** Set the position of all trees logically contained in the expansion of
117134 * inlined call `call` to the position of `call`. This transform is necessary
@@ -159,17 +176,17 @@ object Inlines:
159176 tree
160177 }
161178
162- // assertAllPositioned(tree ) // debug
163- val tree1 = liftBindings(tree , identity)
179+ // assertAllPositioned(tree0 ) // debug
180+ val tree1 = liftBindings(tree0 , identity)
164181 val tree2 =
165182 if bindings.nonEmpty then
166- cpy.Block (tree )(bindings.toList, inlineCall(tree1))
183+ cpy.Block (tree0 )(bindings.toList, inlineCall(tree1))
167184 else if enclosingInlineds.length < ctx.settings.XmaxInlines .value && ! reachedInlinedTreesLimit then
168185 val body =
169- try bodyToInline(tree .symbol) // can typecheck the tree and thereby produce errors
186+ try bodyToInline(tree0 .symbol) // can typecheck the tree and thereby produce errors
170187 catch case _ : MissingInlineInfo =>
171188 throw CyclicReference (ctx.owner)
172- new InlineCall (tree ).expand(body)
189+ new InlineCall (tree0 ).expand(body)
173190 else
174191 ctx.base.stopInlining = true
175192 val (reason, setting) =
0 commit comments