Skip to content

Commit c5cbcb7

Browse files
committed
Ensure function refinement is dependent
1 parent f25c2a3 commit c5cbcb7

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,12 +1191,13 @@ class Definitions {
11911191
}
11921192

11931193
object DependentFunctionRefinementOf {
1194-
/** Matches a refined `FunctionN[...]` or `ContextFunctionN[...]` type and extracts the function type and apply info.
1194+
/** Matches a dependent refinement of `FunctionN[...]` or `ContextFunctionN[...]` type.
1195+
* Extracts the method type type and apply info.
11951196
*
11961197
* Pattern: `$ft { def apply: $mt }`
11971198
*/
11981199
def unapply(ft: Type)(using Context): Option[(Type, MethodType)] = ft.dealias match
1199-
case RefinedType(parent, nme.apply, mt: MethodType) if isFunctionNType(parent) =>
1200+
case RefinedType(parent, nme.apply, mt: MethodType) if isFunctionNType(parent) && mt.isResultDependent =>
12001201
Some((parent, mt))
12011202
case _ => None
12021203
}

tests/neg-custom-args/captures/byname.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
10 | h(f2()) // error
33
| ^^^^
44
| Found: (x$0: Int) ->{cap1} Int
5-
| Required: (x$0: Int) ->{cap2} Int
5+
| Required: Int ->{cap2} Int
66
|
77
| longer explanation available when compiling with `-explain`
88
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/byname.scala:19:5 ----------------------------------------

0 commit comments

Comments
 (0)