Skip to content

Commit 442c3af

Browse files
committed
Avoid NPE in simplify
Fixes #15272 There's no crash anymore, but #15272 still does not compile.
1 parent b61036b commit 442c3af

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
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 != null && tvar.exists then tvar else tp
149149
case _: ThisType | _: BoundType =>
150150
tp
151151
case tp: AliasingBounds =>

tests/neg/i15272.scala

Lines changed: 11 additions & 0 deletions
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)