Skip to content

Commit fe6c299

Browse files
committed
Fix problem when merging denotations with hidden symbols
The hidden test is unreliable after typer, since we cannot guarantee that the current owner is accurate.
1 parent b6d815e commit fe6c299

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ object Denotations {
403403
}
404404
case denot1: SingleDenotation =>
405405
if (denot1 eq denot2) denot1
406-
else if (denot1.matches(denot2)) mergeSingleDenot(denot1, denot2)
406+
else if denot1.matches(denot2) then mergeSingleDenot(denot1, denot2)
407407
else NoDenotation
408408
}
409409

@@ -438,8 +438,11 @@ object Denotations {
438438
else defn.RootClass)
439439

440440
def isHidden(sym: Symbol) = sym.exists && !sym.isAccessibleFrom(pre)
441-
val hidden1 = isHidden(sym1)
442-
val hidden2 = isHidden(sym2)
441+
// In typer phase filter out denotations with symbols that are not
442+
// accessible. After typer, this is not possible since we cannot guarantee
443+
// that the current owner is set correctly. See pos/14660.scala.
444+
val hidden1 = isHidden(sym1) && ctx.isTyper
445+
val hidden2 = isHidden(sym2) && ctx.isTyper
443446
if hidden1 && !hidden2 then denot2
444447
else if hidden2 && !hidden1 then denot1
445448
else

tests/pos/i14660.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait Foo:
2+
class Bar:
3+
private[Foo] opaque type Baz = Int
4+
5+
def foo: Bar#Baz
6+

0 commit comments

Comments
 (0)