Skip to content

Commit cea08f8

Browse files
committed
Fix #7383: Don't include nested classes in class bounds
When computing the class bound in an avoid, we approximate members by refinements. But if the member itself is a class, we cannot refine with Classinfo type. The current fix is to give up in this case and not refine anything. We could try to refine with an abstract type, but in that case we have to be careful with F-bounds.
1 parent 754fa51 commit cea08f8

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ trait TypeAssigner {
5757
.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.info.widenExpr <:< inheritedInfo.widenExpr
63+
&& !(inheritedInfo.widenExpr <:< decl.info.widenExpr)
64+
&& !decl.isClass
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait ZSink {
2+
3+
type State
4+
5+
def foo: ZSink =
6+
class Anon extends ZSink
7+
case class State(x: Int)
8+
new Anon
9+
// new ZSink {
10+
// case class State(x: Int)
11+
// }
12+
}

0 commit comments

Comments
 (0)