File tree 2 files changed +19
-1
lines changed
compiler/src/dotty/tools/dotc/typer
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,15 @@ object Inferencing {
180
180
t match
181
181
case t : TypeRef =>
182
182
if t.symbol == defn.NothingClass then
183
- newTypeVar(TypeBounds .empty, nestingLevel = tvar.nestingLevel)
183
+ val notExactlyNothing = LazyRef (_ => defn.NothingType )
184
+ val bounds = TypeBounds (notExactlyNothing, defn.AnyType )
185
+ // The new type variale has a slightly disguised lower bound Nothing.
186
+ // This foils the `isExactlyNothing` test in `hasLowerBound` and
187
+ // therefore makes the new type variable have a lower bound. That way,
188
+ // we favor in `apply` below instantiating from below to `Nothing` instead
189
+ // of from above to `Any`. That avoids a spurious flip of the original `Nothing`
190
+ // instance to `Any`. See i21275 for a test case.
191
+ newTypeVar(bounds, nestingLevel = tvar.nestingLevel)
184
192
else if t.symbol.is(ModuleClass ) then
185
193
tryWidened(t.parents.filter(! _.isTransparent())
186
194
.foldLeft(defn.AnyType : Type )(TypeComparer .andType(_, _)))
Original file line number Diff line number Diff line change
1
+ class Box [+ O ]:
2
+ def ++ [O2 >: O ](other : Box [O2 ]): Box [O2 ] = ???
3
+ object Box :
4
+ val empty : Box [Nothing ] = ???
5
+
6
+ def test [T ]: Box [T ] =
7
+ List (Box .empty, Box .empty)
8
+ // .reduceOption[Box[T]](_ ++ _) // works
9
+ .reduceOption(_ ++ _) // fails
10
+ .getOrElse(Box .empty)
You can’t perform that action at this time.
0 commit comments