Skip to content

Commit d326f68

Browse files
committed
Avoid crashes due to errors when forming TypeLambdas
After adding star-kind-checking, t3683-modified.scala caused a crash because an ErrorType ended up as the type of a type parameter but a TypeBounds was required. This was possible due to the unsafe cast in LambdaTypeCompanion.fromParams, which this commit eliminates.
1 parent 14d5901 commit d326f68

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2732,20 +2732,27 @@ object Types {
27322732
protected def paramName(param: ParamInfo.Of[N])(implicit ctx: Context): N =
27332733
param.paramName
27342734

2735+
protected def toPInfo(tp: Type)(implicit ctx: Context): PInfo
2736+
27352737
def fromParams[PI <: ParamInfo.Of[N]](params: List[PI], resultType: Type)(implicit ctx: Context): Type =
27362738
if (params.isEmpty) resultType
27372739
else apply(params.map(paramName))(
2738-
tl => params.map(param => tl.integrate(params, param.paramInfo).asInstanceOf[PInfo]),
2740+
tl => params.map(param => toPInfo(tl.integrate(params, param.paramInfo))),
27392741
tl => tl.integrate(params, resultType))
27402742
}
27412743

27422744
abstract class TermLambdaCompanion[LT <: TermLambda]
27432745
extends LambdaTypeCompanion[TermName, Type, LT] {
2746+
def toPInfo(tp: Type)(implicit ctx: Context): Type = tp
27442747
def syntheticParamName(n: Int) = nme.syntheticParamName(n)
27452748
}
27462749

27472750
abstract class TypeLambdaCompanion[LT <: TypeLambda]
27482751
extends LambdaTypeCompanion[TypeName, TypeBounds, LT] {
2752+
def toPInfo(tp: Type)(implicit ctx: Context): TypeBounds = (tp: @unchecked) match {
2753+
case tp: TypeBounds => tp
2754+
case tp: ErrorType => TypeAlias(tp)
2755+
}
27492756
def syntheticParamName(n: Int) = tpnme.syntheticTypeParamName(n)
27502757
}
27512758

0 commit comments

Comments
 (0)