File tree Expand file tree Collapse file tree 4 files changed +17
-6
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 4 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe
195195 case MatchTypeScrutineeCannotBeHigherKindedID // errorNumber: 179
196196 case AmbiguousExtensionMethodID // errorNumber 180
197197 case UnqualifiedCallToAnyRefMethodID // errorNumber: 181
198+ case ClosureCannotHaveInternalParameterDependenciesID // errorNumber: 182
198199
199200 def errorNumber = ordinal - 1
200201
Original file line number Diff line number Diff line change @@ -2906,3 +2906,10 @@ class MatchTypeScrutineeCannotBeHigherKinded(tp: Type)(using Context)
29062906 extends TypeMsg (MatchTypeScrutineeCannotBeHigherKindedID ) :
29072907 def msg (using Context ) = i " the scrutinee of a match type cannot be higher-kinded "
29082908 def explain (using Context ) = " "
2909+
2910+ class ClosureCannotHaveInternalParameterDependencies (mt : Type )(using Context )
2911+ extends TypeMsg (ClosureCannotHaveInternalParameterDependenciesID ):
2912+ def msg (using Context ) =
2913+ i """ cannot turn method type $mt into closure
2914+ |because it has internal parameter dependencies """
2915+ def explain (using Context ) = " "
Original file line number Diff line number Diff line change @@ -1686,19 +1686,20 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16861686 TypeTree (targetTpe)
16871687 case _ =>
16881688 if (mt.isParamDependent)
1689- errorTree(tree,
1690- em """ cannot turn method type $mt into closure
1691- |because it has internal parameter dependencies """ )
1689+ errorTree(tree, ClosureCannotHaveInternalParameterDependencies (mt))
16921690 else if hasCaptureConversionArg(mt.resType) then
16931691 errorTree(tree,
16941692 em """ cannot turn method type $mt into closure
16951693 |because it has capture conversion skolem types """ )
16961694 else
16971695 EmptyTree
16981696 }
1699- case _ : PolyType =>
1700- // Polymorphic SAMs are not currently supported (#6904).
1701- EmptyTree
1697+ case poly @ PolyType (_, mt : MethodType ) =>
1698+ if (mt.isParamDependent)
1699+ errorTree(tree, ClosureCannotHaveInternalParameterDependencies (poly))
1700+ else
1701+ // Polymorphic SAMs are not currently supported (#6904).
1702+ EmptyTree
17021703 case tp =>
17031704 if ! tp.isErroneous then
17041705 throw new java.lang.Error (i " internal error: closing over non-method $tp, pos = ${tree.span}" )
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments