Commit 0397de1
authored
Fix dependent function setup for capture checking (#16542)
Fixes #15925.
This issue is caused by a bug in `mapInferred` during CC `Setup`. In
this function we convert all top-level non-dependent functions to its
dependent counterpart. However, it does not correctly handle the case
when the type is an alias to function types. The problematic case in the
pattern matching:
```scala
case tp @ AppliedType(tycon, args) =>
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)
// ... do the conversion
```
It retrieves the argument and the result type of the function directly
from the applied type arguments. This works for function classes.
However, if the type here is a type alias to the function, e.g. `type
Lazy[X] = Unit => X`, it is still recognized as a function (since
`defn.isNonRefinedFunction` does dealiasing) but it is incorrect to get
the argument and result type of the function from the type parameter
list here (which is just `X :: Nil`).
To fix this, we will dealias the type and recurse when it is an alias to
the function type.File tree
2 files changed
+28
-10
lines changed- compiler/src/dotty/tools/dotc/cc
- tests/neg-custom-args/captures
2 files changed
+28
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
224 | 219 | | |
225 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
226 | 231 | | |
227 | 232 | | |
228 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
0 commit comments