Skip to content

Commit c29e975

Browse files
committed
Fix dotc bootstrap failure
During an attempted dotty bootstrap it was noted that Types.scala did not compile anymore, because `checkUnique` threw a `TypeError` during erasure. The issue was an overloaded member `name` in TermrefWithSig. In NamedType: def name: Name In TermRef: def name: TermName Before erasure, there's one member `name`, after erasure there are two (because after erasure result type counts). The error arose when trying to recompute a member of a `TermRefWithSig` where the name is `name` and the expected signature is `(Nil, ?)`. Since there are two members that match the name and the signature, `checkUnique` triggered a `TypeError`. Before adding `checkUnique`, the previous `atSignature` call would just have returned an arbitrary choice among the two alternative definitions of `name`. The fix is not to use `checkUnique` but to fall back to `d.current` in the case where several alternatives appear. Interestingly, the failure only triggers when -Ycheck options are *disabled*. I added a new test that compiles Types.scala without checks, so we catch this and possibly similar bugs in the future.
1 parent c9ac3d7 commit c29e975

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/dotty/tools/dotc/core/Types.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,11 @@ object Types {
14371437
asMemberOf(prefix) match {
14381438
case NoDenotation => d.current
14391439
case newd: SingleDenotation => newd
1440-
case newd => newd.atSignature(d.signature).checkUnique.orElse(d.current)
1440+
case newd =>
1441+
newd.atSignature(d.signature) match {
1442+
case newd1: SingleDenotation if newd1.exists => newd1
1443+
case _ => d.current
1444+
}
14411445
}
14421446

14431447
private def denotOfSym(sym: Symbol)(implicit ctx: Context): Denotation = {

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class tests extends CompilerTest {
157157
@Test def dotc_ast = compileDir(dotcDir, "ast")
158158
@Test def dotc_config = compileDir(dotcDir, "config")
159159
@Test def dotc_core = compileDir(dotcDir, "core")("-Yno-double-bindings" :: allowDeepSubtypes)// twice omitted to make tests run faster
160+
@Test def dotc_core_Types = compileFile(dotcDir, "core/Types")(noCheckOptions)
160161

161162
// This directory doesn't exist anymore
162163
// @Test def dotc_core_pickling = compileDir(coreDir, "pickling")(allowDeepSubtypes)// twice omitted to make tests run faster

0 commit comments

Comments
 (0)