Skip to content

Commit b8adb72

Browse files
committed
Polymorphic closures cannot have dependencies between value params
Just like for monomorphic closures this isn't currently supported.
1 parent 47aed44 commit b8adb72

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe
196196
case AmbiguousExtensionMethodID // errorNumber 180
197197
case UnqualifiedCallToAnyRefMethodID // errorNumber: 181
198198
case NotConstantID // errorNumber: 182
199+
case ClosureCannotHaveInternalParameterDependenciesID // errorNumber: 183
199200

200201
def errorNumber = ordinal - 1
201202

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,3 +2920,10 @@ class MatchTypeScrutineeCannotBeHigherKinded(tp: Type)(using Context)
29202920
extends TypeMsg(MatchTypeScrutineeCannotBeHigherKindedID) :
29212921
def msg(using Context) = i"the scrutinee of a match type cannot be higher-kinded"
29222922
def explain(using Context) = ""
2923+
2924+
class ClosureCannotHaveInternalParameterDependencies(mt: Type)(using Context)
2925+
extends TypeMsg(ClosureCannotHaveInternalParameterDependenciesID):
2926+
def msg(using Context) =
2927+
i"""cannot turn method type $mt into closure
2928+
|because it has internal parameter dependencies"""
2929+
def explain(using Context) = ""

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,19 +1678,20 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16781678
TypeTree(targetTpe)
16791679
case _ =>
16801680
if (mt.isParamDependent)
1681-
errorTree(tree,
1682-
em"""cannot turn method type $mt into closure
1683-
|because it has internal parameter dependencies""")
1681+
errorTree(tree, ClosureCannotHaveInternalParameterDependencies(mt))
16841682
else if hasCaptureConversionArg(mt.resType) then
16851683
errorTree(tree,
16861684
em"""cannot turn method type $mt into closure
16871685
|because it has capture conversion skolem types""")
16881686
else
16891687
EmptyTree
16901688
}
1691-
case _: PolyType =>
1692-
// Polymorphic SAMs are not currently supported (#6904).
1693-
EmptyTree
1689+
case poly @ PolyType(_, mt: MethodType) =>
1690+
if (mt.isParamDependent)
1691+
errorTree(tree, ClosureCannotHaveInternalParameterDependencies(poly))
1692+
else
1693+
// Polymorphic SAMs are not currently supported (#6904).
1694+
EmptyTree
16941695
case tp =>
16951696
if !tp.isErroneous then
16961697
throw new java.lang.Error(i"internal error: closing over non-method $tp, pos = ${tree.span}")

tests/neg/polymorphic-functions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ object Test {
22
val pv0: [T] => List[T] = ??? // error
33
val pv1: Any = [T] => Nil // error
44
val pv2: [T] => List[T] = [T] => Nil // error // error
5+
6+
val intraDep = [T] => (x: T, y: List[x.type]) => List(y) // error
57
}

0 commit comments

Comments
 (0)