Skip to content

Commit 96e4c74

Browse files
committed
fix dependent function setup in CC Setup
1 parent c3097af commit 96e4c74

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,22 @@ extends tpd.TreeTraverser:
212212
val tycon1 = this(tycon)
213213
if defn.isNonRefinedFunction(tp) then
214214
// Convert toplevel generic function types to dependent functions
215-
val args0 = args.init
216-
var res0 = args.last
217-
val args1 = mapNested(args0)
218-
val res1 = this(res0)
219-
if isTopLevel then
220-
depFun(tycon1, args1, res1)
221-
.showing(i"add function refinement $tp --> $result", capt)
222-
else if (tycon1 eq tycon) && (args1 eq args0) && (res1 eq res0) then
223-
tp
215+
if !defn.isFunctionSymbol(tp.typeSymbol) && (tp.dealias ne tp) then
216+
// This type is a function after dealiasing, so we dealias and recurse.
217+
// See #15925.
218+
this(tp.dealias)
224219
else
225-
tp.derivedAppliedType(tycon1, args1 :+ res1)
220+
val args0 = args.init
221+
var res0 = args.last
222+
val args1 = mapNested(args0)
223+
val res1 = this(res0)
224+
if isTopLevel then
225+
depFun(tycon1, args1, res1)
226+
.showing(i"add function refinement $tp ($tycon1, $args1, $res1) (${tp.dealias}) --> $result", capt)
227+
else if (tycon1 eq tycon) && (args1 eq args0) && (res1 eq res0) then
228+
tp
229+
else
230+
tp.derivedAppliedType(tycon1, args1 :+ res1)
226231
else
227232
tp.derivedAppliedType(tycon1, args.mapConserve(arg => this(arg)))
228233
case tp @ RefinedType(core, rname, rinfo) if defn.isFunctionType(tp) =>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import language.experimental.captureChecking
2+
3+
class Unit
4+
object unit extends Unit
5+
6+
type Foo[X] = [T] -> (op: X => T) -> T
7+
type Lazy[X] = Unit => X
8+
9+
def force[X](fx: Foo[Lazy[X]]): X =
10+
fx[X](f => f(unit)) // error
11+
12+
def force2[X](fx: Foo[Unit => X]): X =
13+
fx[X](f => f(unit)) // error

0 commit comments

Comments
 (0)