File tree 5 files changed +31
-14
lines changed
5 files changed +31
-14
lines changed Original file line number Diff line number Diff line change @@ -700,15 +700,20 @@ object Types {
700
700
701
701
/** If this is a (possibly aliased, annotated, and/or parameterized) reference to
702
702
* a class, the class type ref, otherwise NoType.
703
+ * @param refinementOK If `true` we also skip non-parameter refinements.
703
704
*/
704
- def underlyingClassRef (implicit ctx : Context ): Type = dealias match {
705
+ def underlyingClassRef (refinementOK : Boolean )( implicit ctx : Context ): Type = dealias match {
705
706
case tp : TypeRef =>
706
707
if (tp.symbol.isClass) tp
707
- else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef
708
+ else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
708
709
else NoType
709
- case tp : TypeVar => tp.underlying.underlyingClassRef
710
- case tp : AnnotatedType => tp.underlying.underlyingClassRef
711
- case tp : RefinedType => tp.underlying.underlyingClassRef
710
+ case tp : AnnotatedType => tp.underlying.underlyingClassRef(refinementOK)
711
+ case tp : RefinedType =>
712
+ if (refinementOK) tp.underlying.underlyingClassRef(refinementOK)
713
+ else {
714
+ val tycon = tp.withoutArgs(tp.argInfos)
715
+ if (tycon eq tp) NoType else tycon.underlyingClassRef(refinementOK)
716
+ }
712
717
case _ => NoType
713
718
}
714
719
Original file line number Diff line number Diff line change @@ -248,7 +248,7 @@ trait Checking {
248
248
* @return `tp` itself if it is a class or trait ref, ObjectClass.typeRef if not.
249
249
*/
250
250
def checkClassTypeWithStablePrefix (tp : Type , pos : Position , traitReq : Boolean )(implicit ctx : Context ): Type =
251
- tp.underlyingClassRef match {
251
+ tp.underlyingClassRef(refinementOK = false ) match {
252
252
case tref : TypeRef =>
253
253
if (ctx.phase <= ctx.refchecksPhase) checkStable(tref.prefix, pos)
254
254
if (traitReq && ! (tref.symbol is Trait )) ctx.error(d " $tref is not a trait " , pos)
Original file line number Diff line number Diff line change @@ -106,14 +106,15 @@ trait Inferencing { this: Checking =>
106
106
* class type reference where the class has a companion module, a reference to
107
107
* that companion module. Otherwise NoType
108
108
*/
109
- def companionRef (tp : Type )(implicit ctx : Context ): Type = tp.underlyingClassRef match {
110
- case tp : TypeRef =>
111
- val companion = tp.classSymbol.companionModule
112
- if (companion.exists)
113
- companion.valRef.asSeenFrom(tp.prefix, companion.symbol.owner)
114
- else NoType
115
- case _ => NoType
116
- }
109
+ def companionRef (tp : Type )(implicit ctx : Context ): Type =
110
+ tp.underlyingClassRef(refinementOK = true ) match {
111
+ case tp : TypeRef =>
112
+ val companion = tp.classSymbol.companionModule
113
+ if (companion.exists)
114
+ companion.valRef.asSeenFrom(tp.prefix, companion.symbol.owner)
115
+ else NoType
116
+ case _ => NoType
117
+ }
117
118
118
119
/** Ensure that the first type in a list of parent types Ps points to a non-trait class.
119
120
* If that's not already the case, add one. The added class type CT is determined as follows.
Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ class tests extends CompilerTest {
107
107
@ Test def neg_cycles = compileFile(negDir, " cycles" , xerrors = 8 )
108
108
@ Test def neg_boundspropagation = compileFile(negDir, " boundspropagation" , xerrors = 4 )
109
109
@ Test def neg_refinedSubtyping = compileFile(negDir, " refinedSubtyping" , xerrors = 2 )
110
+ @ Test def neg_i0248_inherit_refined = compileFile(negDir, " i0248-inherit-refined" , xerrors = 4 )
110
111
111
112
@ Test def dotc = compileDir(dotcDir + " tools/dotc" , twice)(allowDeepSubtypes)
112
113
@ Test def dotc_ast = compileDir(dotcDir + " tools/dotc/ast" , twice)
Original file line number Diff line number Diff line change
1
+ object test {
2
+ class A { type T }
3
+ type X = A { type T = Int }
4
+ class B extends X
5
+ type Y = A & B
6
+ class C extends Y
7
+ type Z = A | B
8
+ class D extends Z
9
+ abstract class E extends ({ val x : Int })
10
+ }
You can’t perform that action at this time.
0 commit comments