diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 9db297324014..7a4213bac17a 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -45,6 +45,8 @@ import reporting.diagnostic.messages.SuperCallsNotAllowedInline * (11) Minimizes `call` fields of `Inline` nodes to just point to the toplevel * class from which code was inlined. * + * (12) Converts GADT bounds into normal type bounds + * * The reason for making this a macro transform is that some functions (in particular * super and protected accessors and instantiation checks) are naturally top-down and * don't lend themselves to the bottom-up approach of a mini phase. The other two functions @@ -52,10 +54,17 @@ import reporting.diagnostic.messages.SuperCallsNotAllowedInline * mini-phase or subfunction of a macro phase equally well. But taken by themselves * they do not warrant their own group of miniphases before pickling. */ -class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTransformer => +class PostTyper extends MacroTransform with SymTransformer { thisTransformer => + import tpd._ + def transformSym(ref: SymDenotation)(implicit ctx: Context): SymDenotation = { + if (ref.is(BindDefinedType) && ctx.gadt.bounds.contains(ref.symbol)) { + ref.copySymDenotation(info = ctx.gadt.bounds.apply(ref.symbol) & ref.info) + } else ref + } + /** the following two members override abstract members in Transform */ override def phaseName: String = "posttyper" diff --git a/tests/pos/i2944.scala b/tests/pos/i2944.scala new file mode 100644 index 000000000000..a6c7a92c7b2d --- /dev/null +++ b/tests/pos/i2944.scala @@ -0,0 +1,10 @@ +trait Map2[K] { + def get(k: K): K = k + def foo: K = { + this match { + case that: Map2[b] => that.get(3.asInstanceOf[b]) + //case that: Map2[c] => that.get(4.asInstanceOf[K]) + case _ => get(5.asInstanceOf[K]) + } + } +}