From 8f4210ebba52eb24cd68447fc002760d91920344 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Mon, 30 Sep 2024 15:07:00 +0200 Subject: [PATCH 1/2] Check parents non-empty before calling reduceLeft --- compiler/src/dotty/tools/dotc/typer/Applications.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 992f283154ca..c8eb5b145db1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1962,7 +1962,9 @@ trait Applications extends Compatibility { def widenPrefix(alt: TermRef): Type = alt.prefix.widen match case pre: (TypeRef | ThisType) if pre.typeSymbol.is(Module) => - pre.parents.reduceLeft(TypeComparer.andType(_, _)) + val ps = pre.parents + if ps.isEmpty then pre + else ps.reduceLeft(TypeComparer.andType(_, _)) case wpre => wpre /** If two alternatives have the same symbol, we pick the one with the most From 63e42d3013c0627953aaded6c1546a89365735c4 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Thu, 3 Oct 2024 16:47:33 +0200 Subject: [PATCH 2/2] Add assertion to ensure: if the parents of a module is empty, it must be a package. --- compiler/src/dotty/tools/dotc/typer/Applications.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index c8eb5b145db1..17be2acc7378 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1963,7 +1963,10 @@ trait Applications extends Compatibility { def widenPrefix(alt: TermRef): Type = alt.prefix.widen match case pre: (TypeRef | ThisType) if pre.typeSymbol.is(Module) => val ps = pre.parents - if ps.isEmpty then pre + if ps.isEmpty then + // The parents of a module class are non-empty, unless the module is a package. + assert(pre.typeSymbol.is(Package), pre) + pre else ps.reduceLeft(TypeComparer.andType(_, _)) case wpre => wpre