Skip to content

Commit 0bce5e5

Browse files
committed
Fix tests
1 parent ddcecd1 commit 0bce5e5

File tree

5 files changed

+19
-43
lines changed

5 files changed

+19
-43
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,11 +1287,14 @@ object Types {
12871287
* then the top-level union isn't widened. This is needed so that type inference can infer nullable types.
12881288
*/
12891289
def widenUnion(using Context): Type = widen match
1290-
case tp @ OrNull(tp1) =>
1291-
// Don't widen `T|Null`, since otherwise we wouldn't be able to infer nullable unions.
1292-
val tp1Widen = tp1.widenUnionWithoutNull
1293-
if (tp1Widen.isRef(defn.AnyClass)) tp1Widen
1294-
else tp.derivedOrType(tp1Widen, defn.NullType)
1290+
case tp: OrType => tp match
1291+
case OrNull(tp1) =>
1292+
// Don't widen `T|Null`, since otherwise we wouldn't be able to infer nullable unions.
1293+
val tp1Widen = tp1.widenUnionWithoutNull
1294+
if (tp1Widen.isRef(defn.AnyClass)) tp1Widen
1295+
else tp.derivedOrType(tp1Widen, defn.NullType)
1296+
case _ =>
1297+
tp.widenUnionWithoutNull
12951298
case tp =>
12961299
tp.widenUnionWithoutNull
12971300

@@ -3497,31 +3500,10 @@ object Types {
34973500
*/
34983501
object OrNull {
34993502
def apply(tp: Type)(using Context) =
3500-
OrType(tp, defn.NullType, soft = false)
3501-
def unapply(tp: OrType)(using Context): Option[Type] =
3502-
if (ctx.explicitNulls) {
3503-
val tp1 = tp.stripNull()
3504-
if tp1 ne tp then Some(tp1) else None
3505-
}
3506-
else None
3507-
}
3508-
3509-
/** An extractor object to pattern match against a Java-nullable union.
3510-
* e.g.
3511-
*
3512-
* (tp: Type) match
3513-
* case OrUncheckedNull(tp1) => // tp had the form `tp1 | UncheckedNull`
3514-
* case _ => // tp was not a Java-nullable union
3515-
*/
3516-
object OrUncheckedNull {
3517-
def apply(tp: Type)(using Context) =
3518-
OrType(tp, defn.UncheckedNullAliasType, soft = false)
3503+
if tp.isNullType then tp else OrType(tp, defn.NullType, soft = false)
35193504
def unapply(tp: Type)(using Context): Option[Type] =
3520-
if (ctx.explicitNulls) {
3521-
val tp1 = tp.stripUncheckedNull
3522-
if tp1 ne tp then Some(tp1) else None
3523-
}
3524-
else None
3505+
val tp1 = tp.stripNull
3506+
if tp1 ne tp then Some(tp1) else None
35253507
}
35263508

35273509
// ----- ExprType and LambdaTypes -----------------------------------

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,18 +477,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
477477
*/
478478
def toNotNullTermRef(tree: Tree, pt: Type)(using Context): Tree = tree.tpe match
479479
case ref: TermRef
480-
if ctx.explicitNulls &&
481-
pt != AssignProto && // Ensure it is not the lhs of Assign
480+
if pt != AssignProto && // Ensure it is not the lhs of Assign
482481
ctx.notNullInfos.impliesNotNull(ref) &&
483482
// If a reference is in the context, it is already trackable at the point we add it.
484483
// Hence, we don't use isTracked in the next line, because checking use out of order is enough.
485484
!ref.usedOutOfOrder =>
486-
val tp1 = ref.widenDealias
487-
val tp2 = tp1.stripNull()
488-
if tp1 ne tp2 then
489-
tree.cast(AndType(ref, tp2))
490-
else
491-
tree
485+
ref match
486+
case OrNull(tpnn) => tree.cast(AndType(ref, tpnn))
487+
case _ => tree
492488
case _ =>
493489
tree
494490

tests/neg/t5702-neg-bad-and-wild.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
| pattern expected
1111
|
1212
| longer explanation available when compiling with `-explain`
13-
-- [E040] Syntax Error: tests/neg/t5702-neg-bad-and-wild.scala:13:23 ---------------------------------------------------
13+
-- [E040] Syntax Error: tests/neg/t5702-neg-bad-and-wild.scala:13:22 ---------------------------------------------------
1414
13 | case List(1, _*3:) => // error // error
15-
| ^
16-
| an identifier expected, but ')' found
15+
| ^
16+
| ')' expected, but ':' found
1717
-- [E032] Syntax Error: tests/neg/t5702-neg-bad-and-wild.scala:15:18 ---------------------------------------------------
1818
15 | case List(x*, 1) => // error: pattern expected
1919
| ^

tests/pos-macros/i11211.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def takeOptionImpl2[T](using Quotes, Type[T]): Unit = '{
1212
def takeOptionImpl[T](o: Expr[Option[T]], default: Expr[T])(using Quotes, Type[T]): Expr[T] = '{
1313
$o match {
1414
case Some(t1) => t1
15-
case None: Option[T] => $default
15+
case None => $default
1616
}
1717
}
1818

tests/pos-special/fatal-warnings/i10994.scala

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)