Skip to content

Fix dependent function setup for capture checking #16542

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
Dec 20, 2022
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
25 changes: 15 additions & 10 deletions compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,22 @@ extends tpd.TreeTraverser:
val tycon1 = this(tycon)
if defn.isNonRefinedFunction(tp) then
// Convert toplevel generic function types to dependent functions
val args0 = args.init
var res0 = args.last
val args1 = mapNested(args0)
val res1 = this(res0)
if isTopLevel then
depFun(tycon1, args1, res1)
.showing(i"add function refinement $tp --> $result", capt)
else if (tycon1 eq tycon) && (args1 eq args0) && (res1 eq res0) then
tp
if !defn.isFunctionSymbol(tp.typeSymbol) && (tp.dealias ne tp) then
// This type is a function after dealiasing, so we dealias and recurse.
// See #15925.
this(tp.dealias)
else
tp.derivedAppliedType(tycon1, args1 :+ res1)
val args0 = args.init
var res0 = args.last
val args1 = mapNested(args0)
val res1 = this(res0)
if isTopLevel then
depFun(tycon1, args1, res1)
.showing(i"add function refinement $tp ($tycon1, $args1, $res1) (${tp.dealias}) --> $result", capt)
else if (tycon1 eq tycon) && (args1 eq args0) && (res1 eq res0) then
tp
else
tp.derivedAppliedType(tycon1, args1 :+ res1)
else
tp.derivedAppliedType(tycon1, args.mapConserve(arg => this(arg)))
case tp @ RefinedType(core, rname, rinfo) if defn.isFunctionType(tp) =>
Expand Down
13 changes: 13 additions & 0 deletions tests/neg-custom-args/captures/i15925.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import language.experimental.captureChecking

class Unit
object unit extends Unit

type Foo[X] = [T] -> (op: X => T) -> T
type Lazy[X] = Unit => X

def force[X](fx: Foo[Lazy[X]]): X =
fx[X](f => f(unit)) // error

def force2[X](fx: Foo[Unit => X]): X =
fx[X](f => f(unit)) // error