Skip to content

Commit d79eb0e

Browse files
authored
Merge pull request #6493 from dotty-staging/fix-checkNonCyclic
Fix #6460: less forcing in checkNonCyclic
2 parents 3aa217f + a11de49 commit d79eb0e

File tree

7 files changed

+41
-20
lines changed

7 files changed

+41
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,12 +1301,12 @@ object Denotations {
13011301
if (owner.exists) {
13021302
val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector)
13031303
if (result.exists) result
1304+
else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
13041305
else {
13051306
val alt =
13061307
if (generateStubs) missingHook(owner.symbol.moduleClass, selector)
13071308
else NoSymbol
13081309
if (alt.exists) alt.denot
1309-
else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
13101310
else MissingRef(owner, selector)
13111311
}
13121312
}

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,9 @@ object SymDenotations {
852852
* During completion, references to moduleClass and sourceModules are stored in
853853
* the completers.
854854
*/
855-
/** The class implementing this module, NoSymbol if not applicable. */
855+
/** If this a module, return the corresponding class, if this is a module, return itself,
856+
* otherwise NoSymbol
857+
*/
856858
final def moduleClass(implicit ctx: Context): Symbol = {
857859
def notFound = {
858860
if (Config.showCompletions) println(s"missing module class for $name: $myInfo")
@@ -870,23 +872,34 @@ object SymDenotations {
870872
}
871873
case _ => notFound
872874
}
873-
else NoSymbol
875+
else if (this is ModuleClass)
876+
symbol
877+
else
878+
NoSymbol
874879
}
875880

876-
/** The module implemented by this module class, NoSymbol if not applicable. */
877-
final def sourceModule(implicit ctx: Context): Symbol = myInfo match {
878-
case ClassInfo(_, _, _, _, selfType) if this is ModuleClass =>
879-
def sourceOfSelf(tp: TypeOrSymbol): Symbol = tp match {
880-
case tp: TermRef => tp.symbol
881-
case tp: Symbol => sourceOfSelf(tp.info)
882-
case tp: RefinedType => sourceOfSelf(tp.parent)
881+
/** If this a module class, return the corresponding module, if this is a module, return itself,
882+
* otherwise NoSymbol
883+
*/
884+
final def sourceModule(implicit ctx: Context): Symbol =
885+
if (this is ModuleClass)
886+
myInfo match {
887+
case ClassInfo(_, _, _, _, selfType) =>
888+
def sourceOfSelf(tp: TypeOrSymbol): Symbol = tp match {
889+
case tp: TermRef => tp.symbol
890+
case tp: Symbol => sourceOfSelf(tp.info)
891+
case tp: RefinedType => sourceOfSelf(tp.parent)
892+
}
893+
sourceOfSelf(selfType)
894+
case info: LazyType =>
895+
info.sourceModule
896+
case _ =>
897+
NoSymbol
883898
}
884-
sourceOfSelf(selfType)
885-
case info: LazyType =>
886-
info.sourceModule
887-
case _ =>
899+
else if (this is ModuleVal)
900+
symbol
901+
else
888902
NoSymbol
889-
}
890903

891904
/** The field accessed by this getter or setter, or if it does not exist, the getter */
892905
def accessedFieldOrGetter(implicit ctx: Context): Symbol = {

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ object Completion {
254254
!sym.isAbsent &&
255255
!sym.isPrimaryConstructor &&
256256
sym.sourceSymbol.exists &&
257-
(!sym.is(Package) || !sym.moduleClass.exists) &&
257+
(!sym.is(Package) || sym.is(ModuleClass)) &&
258258
!sym.is(allOf(Mutable, Accessor)) &&
259259
!sym.isPackageObject &&
260260
!sym.is(Artifact) &&

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ object Checking {
240240
)
241241
case prefix: NamedType =>
242242
(!sym.is(Private) && prefix.derivesFrom(sym.owner)) ||
243-
(!prefix.symbol.isStaticOwner && isInteresting(prefix.prefix))
243+
(!prefix.symbol.moduleClass.isStaticOwner && isInteresting(prefix.prefix))
244244
case SuperType(thistp, _) => isInteresting(thistp)
245245
case AndType(tp1, tp2) => isInteresting(tp1) || isInteresting(tp2)
246246
case OrType(tp1, tp2) => isInteresting(tp1) && isInteresting(tp2)

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
4848
compileDir("compiler/src/dotty/tools/dotc/reporting", withCompilerOptions),
4949
compileDir("compiler/src/dotty/tools/dotc/typer", withCompilerOptions),
5050
compileDir("compiler/src/dotty/tools/dotc/util", withCompilerOptions),
51-
compileDir("compiler/src/dotty/tools/io", withCompilerOptions)
51+
compileDir("compiler/src/dotty/tools/io", withCompilerOptions),
52+
compileList(
53+
"testIssue6460",
54+
List(
55+
"compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala",
56+
"compiler/src/dotty/tools/dotc/core/Types.scala"
57+
),
58+
withCompilerOptions
59+
),
5260
).checkCompile()
5361
}
5462

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
type A = B // error: illegal cyclic reference
1+
type A = B // error: recursion limit exceeded
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
type B = A
1+
type B = A // error: recursion limit exceeded // error: recursion limit exceeded

0 commit comments

Comments
 (0)