Skip to content

Commit 5454110

Browse files
authored
Fix i18629 (#18839)
This PR fixes the minimized test of #18629 that could previously crash the global initialization checker because of empty patterns when matching against `List()`.
2 parents 6f9c933 + 321d7e0 commit 5454110

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Diff for: compiler/src/dotty/tools/dotc/transform/init/Objects.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ object Objects:
14181418
val applyDenot = getMemberMethod(scrutineeType, nme.apply, applyType(elemType))
14191419
val applyRes = call(scrutinee, applyDenot.symbol, TraceValue(Bottom, summon[Trace]) :: Nil, scrutineeType, superType = NoType, needResolve = true)
14201420

1421-
if isWildcardStarArg(pats.last) then
1421+
if isWildcardStarArgList(pats) then
14221422
if pats.size == 1 then
14231423
// call .toSeq
14241424
val toSeqDenot = scrutineeType.member(nme.toSeq).suchThat(_.info.isParameterless)
@@ -1433,7 +1433,8 @@ object Objects:
14331433
end if
14341434
else
14351435
// no patterns like `xs*`
1436-
for pat <- pats do evalPattern(applyRes, pat)
1436+
for pat <- pats do evalPattern(applyRes, pat)
1437+
end if
14371438
end evalSeqPatterns
14381439

14391440

Diff for: tests/init-global/pos/i18629.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Foo {
2+
val bar = List() match {
3+
case List() => ???
4+
case _ => ???
5+
}
6+
}

0 commit comments

Comments
 (0)