Skip to content

Commit 7453962

Browse files
committed
Drop BindDefinedType
1 parent 8b9b455 commit 7453962

File tree

6 files changed

+72
-37
lines changed

6 files changed

+72
-37
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ object Flags {
327327
/** A method that has default params */
328328
final val DefaultParameterized = termFlag(27, "<defaultparam>")
329329

330-
/** A type that is defined by a type bind */
331-
final val BindDefinedType = typeFlag(27, "<bind-defined>")
332-
333330
/** Symbol is inlined */
334331
final val Inline = commonFlag(29, "inline")
335332

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,23 +1077,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10771077
val tparam = tr.symbol
10781078
typr.println(i"narrow gadt bound of $tparam: ${tparam.info} from ${if (isUpper) "above" else "below"} to $bound ${bound.isRef(tparam)}")
10791079
if (bound.isRef(tparam)) false
1080-
else bound match {
1081-
case bound: TypeRef
1082-
if bound.symbol.is(BindDefinedType) &&
1083-
ctx.gadt.bounds.contains(bound.symbol) &&
1084-
!tr.symbol.is(BindDefinedType) =>
1085-
// Avoid having pattern-bound types in gadt bounds,
1086-
// as these might be eliminated once the pattern is typechecked.
1087-
// Pattern-bound type symbols should be narrowed first, only if that fails
1088-
// should symbols in the environment be constrained.
1089-
narrowGADTBounds(bound, tr, !isUpper)
1090-
case _ =>
1091-
val oldBounds = ctx.gadt.bounds(tparam)
1092-
val newBounds =
1093-
if (isUpper) TypeBounds(oldBounds.lo, oldBounds.hi & bound)
1094-
else TypeBounds(oldBounds.lo | bound, oldBounds.hi)
1095-
isSubType(newBounds.lo, newBounds.hi) &&
1096-
{ ctx.gadt.setBounds(tparam, newBounds); true }
1080+
else {
1081+
val oldBounds = ctx.gadt.bounds(tparam)
1082+
val newBounds =
1083+
if (isUpper) TypeBounds(oldBounds.lo, oldBounds.hi & bound)
1084+
else TypeBounds(oldBounds.lo | bound, oldBounds.hi)
1085+
isSubType(newBounds.lo, newBounds.hi) &&
1086+
{ ctx.gadt.setBounds(tparam, newBounds); true }
10971087
}
10981088
}
10991089

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ class TreePickler(pickler: TastyPickler) {
161161
pickleConstant(value)
162162
case tpe: NamedType =>
163163
val sym = tpe.symbol
164-
def pickleDirectRef() = {
165-
writeByte(if (tpe.isType) TYPEREFdirect else TERMREFdirect)
166-
pickleSymRef(sym)
167-
}
168164
def pickleExternalRef(sym: Symbol) = {
169165
def pickleCore() = {
170166
pickleNameAndSig(sym.name, tpe.signature)
@@ -188,17 +184,10 @@ class TreePickler(pickler: TastyPickler) {
188184
writeByte(if (tpe.isType) TYPEREFpkg else TERMREFpkg)
189185
pickleName(sym.fullName)
190186
}
191-
else if (tpe.prefix == NoPrefix)
192-
if (sym is Flags.BindDefinedType) {
193-
registerDef(sym)
194-
writeByte(BIND)
195-
withLength {
196-
pickleName(sym.name)
197-
pickleType(sym.info)
198-
pickleDirectRef()
199-
}
200-
}
201-
else pickleDirectRef()
187+
else if (tpe.prefix == NoPrefix) {
188+
writeByte(if (tpe.isType) TYPEREFdirect else TERMREFdirect)
189+
pickleSymRef(sym)
190+
}
202191
else if (isLocallyDefined(sym)) {
203192
writeByte(if (tpe.isType) TYPEREFsymbol else TERMREFsymbol)
204193
pickleSymRef(sym); pickleType(tpe.prefix)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class TreeUnpickler(reader: TastyReader,
282282
case SUPERtype =>
283283
SuperType(readType(), readType())
284284
case BIND =>
285-
val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType, readType(),
285+
val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, EmptyFlags, readType(),
286286
coord = coordAt(start))
287287
registerSym(start, sym)
288288
if (currentAddr != end) readType()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ class Typer extends Namer
12671267
// with an expected type in typedTyped. The type symbol is eliminated once
12681268
// the enclosing pattern has been typechecked; see `indexPattern` in `typedCase`.
12691269
val wildcardSym = ctx.newPatternBoundSymbol(tpnme.WILDCARD, tree1.tpe, tree.pos)
1270-
untpd.Bind(name, tree1).withType(wildcardSym.typeRef)
1270+
untpd.Bind(tpnme.WILDCARD, tree1).withType(wildcardSym.typeRef)
12711271
}
12721272
else tree1
12731273
}

tests/pickling/i0290-type-bind.scala

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
object foo{
2+
val x = List(1,2,3)
3+
x match {
4+
case t: List[tt] => t.head.asInstanceOf[tt]
5+
}
6+
}
7+
8+
object bar {
9+
10+
class C[T <: Seq[_]]
11+
12+
val x: AnyRef = new C
13+
14+
x match {
15+
case x: C[u] =>
16+
def x: u = x
17+
val s: Seq[_] = x
18+
}
19+
}
20+
21+
object foo2{{
22+
val x = List(1,2,3)
23+
x match {
24+
case t: List[tt] => t.head.asInstanceOf[tt]
25+
}
26+
}}
27+
28+
object bar2 {{
29+
30+
class C[T <: Seq[_]]
31+
32+
val x: AnyRef = new C
33+
34+
x match {
35+
case x: C[u] =>
36+
def x: u = x
37+
val s: Seq[_] = x
38+
}
39+
}}
40+
41+
object foo3{ val x0 = {
42+
val x = List(1,2,3)
43+
x match {
44+
case t: List[tt] => t.head.asInstanceOf[tt]
45+
}
46+
}}
47+
48+
object bar3 { def f0 = {
49+
50+
class C[T <: Seq[_]]
51+
52+
val x: AnyRef = new C
53+
54+
x match {
55+
case x: C[u] =>
56+
def x: u = x
57+
val s: Seq[_] = x
58+
}
59+
}}

0 commit comments

Comments
 (0)