Skip to content

Commit 9220b7e

Browse files
authored
Merge pull request #15310 from dotty-staging/fix-15272
Avoid NPE in simplify
2 parents 591db4d + c55fa8c commit 9220b7e

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
148148
private def paramCount(entries: Array[Type]) = entries.length >> 1
149149

150150
/** The type variable corresponding to parameter numbered `n`, null if none was created */
151-
private def typeVar(entries: Array[Type], n: Int): Type =
151+
private def typeVar(entries: Array[Type], n: Int): Type | Null =
152152
entries(paramCount(entries) + n)
153153

154154
/** The `boundsMap` entry corresponding to `param` */
@@ -203,11 +203,13 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
203203
def nonParamBounds(param: TypeParamRef)(using Context): TypeBounds =
204204
entry(param).bounds
205205

206-
def typeVarOfParam(param: TypeParamRef): Type = {
206+
def typeVarOfParam(param: TypeParamRef): Type =
207207
val entries = boundsMap(param.binder)
208208
if entries == null then NoType
209-
else typeVar(entries, param.paramNum)
210-
}
209+
else
210+
val tvar = typeVar(entries, param.paramNum)
211+
if tvar == null then NoType
212+
else tvar
211213

212214
// ---------- Adding TypeLambdas --------------------------------------------------
213215

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ object TypeOps:
145145
if normed.exists then normed else tp.map(simplify(_, theMap))
146146
case tp: TypeParamRef =>
147147
val tvar = ctx.typerState.constraint.typeVarOfParam(tp)
148-
if (tvar.exists) tvar else tp
148+
if tvar.exists then tvar else tp
149149
case _: ThisType | _: BoundType =>
150150
tp
151151
case tp: AliasingBounds =>

tests/neg/i15272.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sealed trait EdgeN[+NT]
2+
object EdgeN:
3+
case class Head[+NT, +From <: NT, +To <: NT] (from: From, to: To ) extends EdgeN[NT]
4+
case class Cons[+NT, +From <: NT, +ToE <: EdgeN[NT]](from: From, to: ToE) extends EdgeN[NT]
5+
final type InNodesTupleOf[NT, E <: EdgeN[NT]] <: Tuple = E match
6+
case Cons[nt,from,toE] => from *: InNodesTupleOf[nt,toE]
7+
case Head[nt,from ,to] => from *: EmptyTuple
8+
def inNodesTuple[NT,E <: EdgeN[NT]](edge: E): InNodesTupleOf[NT,E] = edge match
9+
case e: Cons[nt,from,toE] => e.from *: inNodesTuple[nt,toE](e.to) // error
10+
case e: Head[nt,from,to] => e.from *: EmptyTuple
11+
end EdgeN

0 commit comments

Comments
 (0)