@@ -1912,32 +1912,34 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1912
1912
val untpd .Function (vparams : List [untpd.ValDef ] @ unchecked, body) = fun : @ unchecked
1913
1913
val dpt = pt.dealias
1914
1914
1915
- // If the expected type is a polymorphic function with the same number of
1916
- // type and value parameters, then infer the types of value parameters from the expected type.
1917
- val inferredVParams = dpt match
1918
- case defn.PolyFunctionOf (poly @ PolyType (_, mt : MethodType ))
1919
- if tparams.lengthCompare(poly.paramNames) == 0 && vparams.lengthCompare(mt.paramNames) == 0 =>
1920
- vparams.zipWithConserve(mt.paramInfos): (vparam, formal) =>
1921
- // Unlike in typedFunctionValue, `formal` cannot be a TypeBounds since
1922
- // it must be a valid method parameter type.
1923
- if vparam.tpt.isEmpty && isFullyDefined(formal, ForceDegree .failBottom) then
1924
- cpy.ValDef (vparam)(tpt = new untpd.InLambdaTypeTree (isResult = false , (tsyms, vsyms) =>
1925
- // We don't need to substitute `mt` by `vsyms` because we currently disallow
1926
- // dependencies between value parameters of a closure.
1927
- formal.substParams(poly, tsyms.map(_.typeRef)))
1928
- )
1929
- else vparam
1930
- case _ =>
1931
- vparams
1932
-
1933
- val resultTpt = dpt match
1915
+ dpt match
1934
1916
case defn.PolyFunctionOf (poly @ PolyType (_, mt : MethodType )) =>
1935
- untpd.InLambdaTypeTree (isResult = true , (tsyms, vsyms) =>
1936
- mt.resultType.substParams(mt, vsyms.map(_.termRef)).substParams(poly, tsyms.map(_.typeRef)))
1937
- case _ => untpd.TypeTree ()
1938
-
1939
- val desugared = desugar.makeClosure(tparams, inferredVParams, body, resultTpt, tree.span)
1940
- typed(desugared, pt)
1917
+ if tparams.lengthCompare(poly.paramNames) == 0 && vparams.lengthCompare(mt.paramNames) == 0 then
1918
+ // If the expected type is a polymorphic function with the same number of
1919
+ // type and value parameters, then infer the types of value parameters from the expected type.
1920
+ val inferredVParams = vparams.zipWithConserve(mt.paramInfos): (vparam, formal) =>
1921
+ // Unlike in typedFunctionValue, `formal` cannot be a TypeBounds since
1922
+ // it must be a valid method parameter type.
1923
+ if vparam.tpt.isEmpty && isFullyDefined(formal, ForceDegree .failBottom) then
1924
+ cpy.ValDef (vparam)(tpt = new untpd.InLambdaTypeTree (isResult = false , (tsyms, vsyms) =>
1925
+ // We don't need to substitute `mt` by `vsyms` because we currently disallow
1926
+ // dependencies between value parameters of a closure.
1927
+ formal.substParams(poly, tsyms.map(_.typeRef)))
1928
+ )
1929
+ else vparam
1930
+ val resultTpt =
1931
+ untpd.InLambdaTypeTree (isResult = true , (tsyms, vsyms) =>
1932
+ mt.resultType.substParams(mt, vsyms.map(_.termRef)).substParams(poly, tsyms.map(_.typeRef)))
1933
+ val desugared = desugar.makeClosure(tparams, inferredVParams, body, resultTpt, tree.span)
1934
+ typed(desugared, pt)
1935
+ else
1936
+ val msg =
1937
+ em """ |Provided polymorphic function value doesn't match the expected type $dpt.
1938
+ |Expected type should be a polymorphic function with the same number of type and value parameters. """
1939
+ errorTree(EmptyTree , msg, tree.srcPos)
1940
+ case _ =>
1941
+ val desugared = desugar.makeClosure(tparams, vparams, body, untpd.TypeTree (), tree.span)
1942
+ typed(desugared, pt)
1941
1943
end typedPolyFunctionValue
1942
1944
1943
1945
def typedClosure (tree : untpd.Closure , pt : Type )(using Context ): Tree = {
0 commit comments