@@ -749,9 +749,9 @@ class Inliner(val call: tpd.Tree)(using Context):
749749 ctx
750750
751751 override def typedIdent (tree : untpd.Ident , pt : Type )(using Context ): Tree =
752- val tree1 = inlineIfNeeded(
753- tryInlineArg(tree.asInstanceOf [tpd.Tree ]) `orElse` super .typedIdent(tree, pt)
754- )
752+ val locked = ctx.typerState.ownedVars
753+ val tree0 = tryInlineArg(tree.asInstanceOf [tpd.Tree ]) `orElse` super .typedIdent(tree, pt)
754+ val tree1 = inlineIfNeeded(tree0, pt, locked )
755755 tree1 match
756756 case id : Ident if tpd.needsSelect(id.tpe) =>
757757 inlining.println(i " expanding $id to selection " )
@@ -760,6 +760,7 @@ class Inliner(val call: tpd.Tree)(using Context):
760760 tree1
761761
762762 override def typedSelect (tree : untpd.Select , pt : Type )(using Context ): Tree = {
763+ val locked = ctx.typerState.ownedVars
763764 val qual1 = typed(tree.qualifier, shallowSelectionProto(tree.name, pt, this ))
764765 val resNoReduce = untpd.cpy.Select (tree)(qual1, tree.name).withType(tree.typeOpt)
765766 val reducedProjection = reducer.reduceProjection(resNoReduce)
@@ -771,7 +772,7 @@ class Inliner(val call: tpd.Tree)(using Context):
771772 if resNoReduce ne res then
772773 typed(res, pt) // redo typecheck if reduction changed something
773774 else if res.symbol.isInlineMethod then
774- inlineIfNeeded(res)
775+ inlineIfNeeded(res, pt, locked )
775776 else
776777 ensureAccessible(res.tpe, tree.qualifier.isInstanceOf [untpd.Super ], tree.srcPos)
777778 res
@@ -809,19 +810,21 @@ class Inliner(val call: tpd.Tree)(using Context):
809810 tree match
810811 case Quoted (Spliced (inner)) => inner
811812 case _ => tree
813+ val locked = ctx.typerState.ownedVars
812814 val res = cancelQuotes(constToLiteral(betaReduce(super .typedApply(tree, pt)))) match {
813815 case res : Apply if res.symbol == defn.QuotedRuntime_exprSplice
814816 && StagingContext .level == 0
815817 && ! hasInliningErrors =>
816818 val expanded = expandMacro(res.args.head, tree.srcPos)
817819 typedExpr(expanded) // Inline calls and constant fold code generated by the macro
818820 case res =>
819- specializeEq(inlineIfNeeded(res))
821+ specializeEq(inlineIfNeeded(res, pt, locked ))
820822 }
821823 res
822824
823825 override def typedTypeApply (tree : untpd.TypeApply , pt : Type )(using Context ): Tree =
824- val tree1 = inlineIfNeeded(constToLiteral(betaReduce(super .typedTypeApply(tree, pt))))
826+ val locked = ctx.typerState.ownedVars
827+ val tree1 = inlineIfNeeded(constToLiteral(betaReduce(super .typedTypeApply(tree, pt))), pt, locked)
825828 if tree1.symbol.isQuote then
826829 ctx.compilationUnit.needsStaging = true
827830 tree1
@@ -889,11 +892,11 @@ class Inliner(val call: tpd.Tree)(using Context):
889892 /** True if this inline typer has already issued errors */
890893 override def hasInliningErrors (using Context ) = ctx.reporter.errorCount > initialErrorCount
891894
892- private def inlineIfNeeded (tree : Tree )(using Context ): Tree =
895+ private def inlineIfNeeded (tree : Tree , pt : Type , locked : TypeVars )(using Context ): Tree =
893896 val meth = tree.symbol
894897 if meth.isAllOf(DeferredInline ) then
895898 errorTree(tree, em " Deferred inline ${meth.showLocated} cannot be invoked " )
896- else if Inlines .needsInlining(tree) then Inlines .inlineCall(tree)
899+ else if Inlines .needsInlining(tree) then Inlines .inlineCall(simplify( tree, pt, locked) )
897900 else tree
898901
899902 override def typedUnadapted (tree : untpd.Tree , pt : Type , locked : TypeVars )(using Context ): Tree =
0 commit comments