File tree Expand file tree Collapse file tree 2 files changed +27
-16
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +27
-16
lines changed Original file line number Diff line number Diff line change @@ -89,32 +89,29 @@ object Inferencing {
89
89
* to their upper bound.
90
90
*/
91
91
private class IsFullyDefinedAccumulator (force : ForceDegree .Value )(implicit ctx : Context ) extends TypeAccumulator [Boolean ] {
92
+
92
93
private def instantiate (tvar : TypeVar , fromBelow : Boolean ): Type = {
93
94
val inst = tvar.instantiate(fromBelow)
94
95
typr.println(i " forced instantiation of ${tvar.origin} = $inst" )
95
96
inst
96
97
}
98
+
97
99
private [this ] var toMaximize : Boolean = false
100
+
98
101
def apply (x : Boolean , tp : Type ): Boolean = tp.dealias match {
99
102
case _ : WildcardType | _ : ProtoType =>
100
103
false
101
104
case tvar : TypeVar
102
105
if ! tvar.isInstantiated && ctx.typerState.constraint.contains(tvar) =>
103
106
force.appliesTo(tvar) && {
104
- val direction = instDirection(tvar.origin)
105
- if (direction != 0 ) {
106
- // if (direction > 0) println(s"inst $tvar dir = up")
107
- instantiate(tvar, direction < 0 )
108
- }
109
- else {
110
- val minimize =
111
- force.minimizeAll ||
112
- variance >= 0 && ! (
113
- ! force.allowBottom &&
114
- defn.isBottomType(ctx.typeComparer.approximation(tvar.origin, fromBelow = true )))
115
- if (minimize) instantiate(tvar, fromBelow = true )
116
- else toMaximize = true
117
- }
107
+ val pref = tvar.origin
108
+ def avoidBottom =
109
+ ! force.allowBottom &&
110
+ defn.isBottomType(ctx.typeComparer.approximation(pref, fromBelow = true ))
111
+ def preferMax =
112
+ instDirection(pref) > 0 || variance >= 0 && avoidBottom
113
+ if (force.minimizeAll || ! preferMax) instantiate(tvar, fromBelow = true )
114
+ else toMaximize = true
118
115
foldOver(x, tvar)
119
116
}
120
117
case tp =>
Original file line number Diff line number Diff line change
1
+ import reflect .ClassTag
2
+ class Co [+ S ]
3
+ object Co {
4
+ def empty [X : ClassTag ]: Co [X ] = ???
5
+ }
6
+ class Contra [- S ]
7
+ object Contra {
8
+ def empty [X : ClassTag ]: Contra [X ] = ???
9
+ }
1
10
class Foo [+ FT ](x : FT ) {
2
11
def fooArray : Foo [Array [String ]] = new Foo (Array .empty)
3
- val y : Array [String ] = Array .empty
4
- }
12
+ val y1 : Array [String ] = Array .empty
13
+ def fooCo : Foo [Co [String ]] = new Foo (Co .empty)
14
+ val y2 : Co [String ] = Co .empty
15
+ def fooContra : Foo [Contra [String ]] = new Foo (Contra .empty)
16
+ val y3 : Contra [String ] = Contra .empty
17
+ }
18
+
You can’t perform that action at this time.
0 commit comments