Skip to content

Commit 07bbf7b

Browse files
authored
Merge pull request #7397 from dotty-staging/fix-#7383
Fix #7383: Don't include nested classes in class bounds
2 parents cef08d9 + 45aba5c commit 07bbf7b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,19 @@ trait TypeAssigner {
5353
def addRefinement(parent: Type, decl: Symbol) = {
5454
val inherited =
5555
parentType.findMember(decl.name, cls.thisType,
56-
required = EmptyFlags, excluded = Private)
57-
.suchThat(decl.matches(_))
56+
required = EmptyFlags, excluded = Private
57+
).suchThat(decl.matches(_))
5858
val inheritedInfo = inherited.info
5959
val isPolyFunctionApply = decl.name == nme.apply && (parent <:< defn.PolyFunctionType)
60-
if (isPolyFunctionApply || inheritedInfo.exists &&
61-
decl.info.widenExpr <:< inheritedInfo.widenExpr &&
62-
!(inheritedInfo.widenExpr <:< decl.info.widenExpr)) {
60+
if isPolyFunctionApply
61+
|| inheritedInfo.exists
62+
&& !decl.isClass
63+
&& decl.info.widenExpr <:< inheritedInfo.widenExpr
64+
&& !(inheritedInfo.widenExpr <:< decl.info.widenExpr)
65+
then
6366
val r = RefinedType(parent, decl.name, decl.info)
6467
typr.println(i"add ref $parent $decl --> " + r)
6568
r
66-
}
6769
else
6870
parent
6971
}

tests/pos/i7383.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait ZSink {
2+
3+
type State
4+
5+
def foo: ZSink =
6+
class Anon extends ZSink {
7+
case class State(x: Int)
8+
}
9+
new Anon
10+
11+
def foo2: ZSink =
12+
new ZSink {
13+
case class State(x: Int)
14+
}
15+
}

0 commit comments

Comments
 (0)