Skip to content

Commit 685e0e7

Browse files
committed
Relax nullability checks on FlexibleTypes
1 parent 3da7bb1 commit 685e0e7

File tree

7 files changed

+8
-8
lines changed

7 files changed

+8
-8
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ object CaptureSet:
942942
* is not derived from some other variable.
943943
*/
944944
protected def ids(using Context): String =
945-
def descr = getClass.getSimpleName.nn.take(1)
945+
def descr = getClass.getSimpleName.take(1)
946946
val trail = this.match
947947
case dv: DerivedVar =>
948948
def summary = if ctx.settings.YccVerbose.value then dv.summarize else descr

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object NullOpsDecorator:
4747

4848
/** Is self (after widening and dealiasing) a type of the form `T | Null`? */
4949
def isNullableUnion(using Context): Boolean = {
50-
val stripped = self.stripNull()
50+
val stripped = self.stripNull(stripFlexibleTypes = false)
5151
stripped ne self
5252
}
5353
end extension

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ object SymbolLoaders {
322322
val fullName = pkg.name
323323
val name =
324324
if (packageName.isEmpty) fullName
325-
else fullName.substring(packageName.length + 1).nn
325+
else fullName.substring(packageName.length + 1)
326326

327327
enterPackage(root.symbol, name.toTermName,
328328
(module, modcls) => new PackageLoader(module, classPath))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,12 +3376,12 @@ object TypeComparer {
33763376
}
33773377

33783378
private[core] def show(res: Any)(using Context): String =
3379-
if ctx.settings.YexplainLowlevel.value then String.valueOf(res).nn
3379+
if ctx.settings.YexplainLowlevel.value then String.valueOf(res)
33803380
else res match
33813381
case ClassInfo(_, cls, _, _, _) => cls.showLocated
33823382
case bounds: TypeBounds => i"type bounds [$bounds]"
33833383
case res: printing.Showable => res.show
3384-
case _ => String.valueOf(res).nn
3384+
case _ => String.valueOf(res)
33853385

33863386
/** The approximation state indicates how the pair of types currently compared
33873387
* relates to the types compared originally.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ object Types extends TypeUtils {
382382
/** Is this type guaranteed not to have `null` as a value? */
383383
final def isNotNull(using Context): Boolean = this match {
384384
case tp: ConstantType => tp.value.value != null
385-
case tp: FlexibleType => false
385+
case tp: FlexibleType => true
386386
case tp: ClassInfo => !tp.cls.isNullableClass && !tp.isNothingType
387387
case tp: AppliedType => tp.superType.isNotNull
388388
case tp: TypeBounds => tp.hi.isNotNull

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
12101210
}
12111211
catch {
12121212
case ex: FromDigitsException =>
1213-
report.error(ex.getMessage.nn, tree.srcPos)
1213+
report.error(ex.getMessage, tree.srcPos)
12141214
tree.kind match {
12151215
case Whole(_) => lit(0)
12161216
case _ => lit(0.0)

tests/explicit-nulls/warn/unnecessary-nn.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def f5a[T <: String](s: T): String = s.nn // warn
1010

1111
// flexible types
1212
def f7(s: String|Null): String = "".concat(s.nn) // warn
13-
def f8(s: String): String = s.trim().nn // OK because the .nn could be useful as a dynamic null check
13+
def f8(s: String): String = s.trim().nn // warn
1414

1515

1616
def f9(s: String|Null): String =

0 commit comments

Comments
 (0)