File tree 5 files changed +29
-6
lines changed
compiler/src/dotty/tools/dotc/core
5 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -148,21 +148,24 @@ class CheckRealizable(using Context) {
148
148
*/
149
149
private def boundsRealizability (tp : Type ) = {
150
150
151
- val memberProblems =
151
+ val memberProblems = withMode( Mode . CheckBounds ) {
152
152
for {
153
153
mbr <- tp.nonClassTypeMembers
154
154
if ! (mbr.info.loBound <:< mbr.info.hiBound)
155
155
}
156
156
yield new HasProblemBounds (mbr.name, mbr.info)
157
+ }
157
158
158
- val refinementProblems =
159
+ val refinementProblems = withMode( Mode . CheckBounds ) {
159
160
for {
160
161
name <- refinedNames(tp)
161
162
if (name.isTypeName)
162
163
mbr <- tp.member(name).alternatives
163
164
if ! (mbr.info.loBound <:< mbr.info.hiBound)
164
165
}
165
- yield new HasProblemBounds (name, mbr.info)
166
+ yield
167
+ new HasProblemBounds (name, mbr.info)
168
+ }
166
169
167
170
def baseTypeProblems (base : Type ) = base match {
168
171
case AndType (base1, base2) =>
Original file line number Diff line number Diff line change @@ -72,6 +72,11 @@ object Mode {
72
72
/** We are currently unpickling Scala2 info */
73
73
val Scala2Unpickling : Mode = newMode(13 , " Scala2Unpickling" )
74
74
75
+ /** We are currently checking bounds to be non-empty, so we should not
76
+ * do any widening when computing members of refined types.
77
+ */
78
+ val CheckBounds : Mode = newMode(14 , " CheckBounds" )
79
+
75
80
/** Use Scala2 scheme for overloading and implicit resolution */
76
81
val OldOverloadingResolution : Mode = newMode(15 , " OldOverloadingResolution" )
77
82
Original file line number Diff line number Diff line change @@ -507,7 +507,7 @@ object TypeOps:
507
507
boundss : List [TypeBounds ],
508
508
instantiate : (Type , List [Type ]) => Type ,
509
509
app : Type )(
510
- using Context ): List [BoundsViolation ] = {
510
+ using Context ): List [BoundsViolation ] = withMode( Mode . CheckBounds ) {
511
511
val argTypes = args.tpes
512
512
513
513
/** Replace all wildcards in `tps` with `<app>#<tparam>` where `<tparam>` is the
Original file line number Diff line number Diff line change @@ -671,8 +671,16 @@ object Types {
671
671
val rinfo = tp.refinedInfo
672
672
if (name.isTypeName && ! pinfo.isInstanceOf [ClassInfo ]) { // simplified case that runs more efficiently
673
673
val jointInfo =
674
- if (ctx.base.pendingMemberSearches.contains(name)) pinfo safe_& rinfo
675
- else pinfo recoverable_& rinfo
674
+ if rinfo.isInstanceOf [TypeAlias ] && ! ctx.mode.is(Mode .CheckBounds ) then
675
+ // In normal situations, the only way to "improve" on rinfo is to return an empty type bounds
676
+ // So, we do not lose anything essential in "widening" to rinfo.
677
+ // We need to compute the precise info only when checking for empty bounds
678
+ // which is communicated by the CheckBounds mode.
679
+ rinfo
680
+ else if ctx.base.pendingMemberSearches.contains(name) then
681
+ pinfo safe_& rinfo
682
+ else
683
+ pinfo recoverable_& rinfo
676
684
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
677
685
}
678
686
else
Original file line number Diff line number Diff line change
1
+ trait Foo {
2
+ type Repr [+ O ] <: Foo {
3
+ type Repr [+ OO ] = Foo .this .Repr [OO ]
4
+ }
5
+
6
+ def foo [T ](f : Repr [T ]): f.Repr [T ] = ???
7
+ }
You can’t perform that action at this time.
0 commit comments