Skip to content

Commit 0802abd

Browse files
Merge pull request #2958 from dotty-staging/fix-2944
Fix #2944: propagate information from GADT bounds to normal info.
2 parents a1f3744 + 1c0f63f commit 0802abd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,26 @@ import reporting.diagnostic.messages.SuperCallsNotAllowedInline
4545
* (11) Minimizes `call` fields of `Inline` nodes to just point to the toplevel
4646
* class from which code was inlined.
4747
*
48+
* (12) Converts GADT bounds into normal type bounds
49+
*
4850
* The reason for making this a macro transform is that some functions (in particular
4951
* super and protected accessors and instantiation checks) are naturally top-down and
5052
* don't lend themselves to the bottom-up approach of a mini phase. The other two functions
5153
* (forwarding param accessors and synthetic methods) only apply to templates and fit
5254
* mini-phase or subfunction of a macro phase equally well. But taken by themselves
5355
* they do not warrant their own group of miniphases before pickling.
5456
*/
55-
class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTransformer =>
57+
class PostTyper extends MacroTransform with SymTransformer { thisTransformer =>
58+
5659

5760
import tpd._
5861

62+
def transformSym(ref: SymDenotation)(implicit ctx: Context): SymDenotation = {
63+
if (ref.is(BindDefinedType) && ctx.gadt.bounds.contains(ref.symbol)) {
64+
ref.copySymDenotation(info = ctx.gadt.bounds.apply(ref.symbol) & ref.info)
65+
} else ref
66+
}
67+
5968
/** the following two members override abstract members in Transform */
6069
override def phaseName: String = "posttyper"
6170

tests/pos/i2944.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trait Map2[K] {
2+
def get(k: K): K = k
3+
def foo: K = {
4+
this match {
5+
case that: Map2[b] => that.get(3.asInstanceOf[b])
6+
//case that: Map2[c] => that.get(4.asInstanceOf[K])
7+
case _ => get(5.asInstanceOf[K])
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)