Skip to content

Make inline proxy vals have inferred types #20241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,16 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
def setupTraverser(recheckDef: DefRecheck) = new TreeTraverserWithPreciseImportContexts:

def transformResultType(tpt: TypeTree, sym: Symbol)(using Context): Unit =
transformTT(tpt,
boxed = !ccConfig.allowUniversalInBoxed && sym.is(Mutable, butNot = Method),
// types of mutable variables are boxed in pre 3.3 codee
exact = sym.allOverriddenSymbols.hasNext,
// types of symbols that override a parent don't get a capture set TODO drop
)
try
transformTT(tpt,
boxed = !ccConfig.allowUniversalInBoxed && sym.is(Mutable, butNot = Method),
// types of mutable variables are boxed in pre 3.3 codee
exact = sym.allOverriddenSymbols.hasNext,
// types of symbols that override a parent don't get a capture set TODO drop
)
catch case ex: IllegalCaptureRef =>
capt.println(i"fail while transforming result type $tpt of $sym")
throw ex
val addDescription = new TypeTraverser:
def traverse(tp: Type) = tp match
case tp @ CapturingType(parent, refs) =>
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class Inliner(val call: tpd.Tree)(using Context):
if bindingFlags.is(Inline) && argIsBottom then
newArg = Typed(newArg, TypeTree(formal.widenExpr)) // type ascribe RHS to avoid type errors in expansion. See i8612.scala
if isByName then DefDef(boundSym, newArg)
else ValDef(boundSym, newArg)
else ValDef(boundSym, newArg, inferred = true)
}.withSpan(boundSym.span)
inlining.println(i"parameter binding: $binding, $argIsBottom")
buf += binding
Expand Down Expand Up @@ -319,7 +319,7 @@ class Inliner(val call: tpd.Tree)(using Context):
else pre

val binding = accountForOpaques(
ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span))
ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym), inferred = true).withSpan(selfSym.span))
bindingsBuf += binding
inlining.println(i"proxy at $level: $selfSym = ${bindingsBuf.last}")
lastSelf = selfSym
Expand Down Expand Up @@ -368,7 +368,7 @@ class Inliner(val call: tpd.Tree)(using Context):
RefinedType(parent, refinement._1, TypeAlias(refinement._2))
)
val refiningSym = newSym(InlineBinderName.fresh(), Synthetic, refinedType).asTerm
val refiningDef = ValDef(refiningSym, tpd.ref(ref).cast(refinedType)).withSpan(span)
val refiningDef = ValDef(refiningSym, tpd.ref(ref).cast(refinedType), inferred = true).withSpan(span)
inlining.println(i"add opaque alias proxy $refiningDef for $ref in $tp")
bindingsBuf += refiningDef
opaqueProxies += ((ref, refiningSym.termRef))
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i20237.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import language.experimental.captureChecking
import scala.annotation.capability

@capability class Cap:
def use[T](body: Cap ?=> T) = body(using this)

class Box[T](body: Cap ?=> T):
inline def open(using cap: Cap) = cap.use(body)

object Box:
def make[T](body: Cap ?=> T)(using Cap): Box[T]^{body} = Box(body)

def main =
given Cap = new Cap
val box = Box.make(1).open
Loading