Skip to content

Commit f62992c

Browse files
committed
Another fix for isInaccessibleChildOf
1 parent 56fbf01 commit f62992c

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,14 @@ class SymUtils(val self: Symbol) extends AnyVal {
179179
* it cannot be seen from parent class `cls`?
180180
*/
181181
def isInaccessibleChildOf(cls: Symbol)(given Context): Boolean =
182-
def isAccessible(sym: Symbol): Boolean =
183-
sym == cls
184-
|| sym == cls.owner
185-
|| sym.is(Package)
186-
|| sym.isType && isAccessible(sym.owner)
187-
!isAccessible(self.owner)
182+
def isAccessible(sym: Symbol, cls: Symbol): Boolean =
183+
if cls.isType && !cls.is(Package) then
184+
isAccessible(sym, cls.owner)
185+
else
186+
sym == cls
187+
|| sym.is(Package)
188+
|| sym.isType && isAccessible(sym.owner, cls)
189+
!isAccessible(self.owner, cls)
188190

189191
/** If this is a sealed class, its known children in the order of textual occurrence */
190192
def children(implicit ctx: Context): List[Symbol] = {

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,17 +2103,19 @@ class Typer extends Namer
21032103
}
21042104

21052105
val ifpt = defn.asImplicitFunctionType(pt)
2106-
val result = if (ifpt.exists &&
2107-
xtree.isTerm &&
2108-
!untpd.isContextualClosure(xtree) &&
2109-
!ctx.mode.is(Mode.Pattern) &&
2110-
!ctx.isAfterTyper &&
2111-
!ctx.isInlineContext)
2112-
makeContextualFunction(xtree, ifpt)
2113-
else xtree match {
2114-
case xtree: untpd.NameTree => typedNamed(xtree, pt)
2115-
case xtree => typedUnnamed(xtree)
2116-
}
2106+
val result =
2107+
if ifpt.exists
2108+
&& xtree.isTerm
2109+
&& !untpd.isContextualClosure(xtree)
2110+
&& !ctx.mode.is(Mode.Pattern)
2111+
&& !ctx.isAfterTyper
2112+
&& !ctx.isInlineContext
2113+
then
2114+
makeContextualFunction(xtree, ifpt)
2115+
else xtree match
2116+
case xtree: untpd.NameTree => typedNamed(xtree, pt)
2117+
case xtree => typedUnnamed(xtree)
2118+
21172119
simplify(result, pt, locked)
21182120
}
21192121
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def foo: Unit =
2+
object O
3+
sealed abstract class A
4+
class B extends O.A
5+
class C extends O.A
6+
7+
val x: O.A = ???
8+
x match
9+
case x: B => ???
10+
case x: C => ???

0 commit comments

Comments
 (0)