Skip to content

Commit 6542458

Browse files
committed
Merge pull request #283 from dotty-staging/fix/#291-null-primitive-conforms
Disable implicit conversions between from `Null` and `Nothing`.
2 parents f3d887f + 9f87127 commit 6542458

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ trait Implicits { self: Typer =>
400400
def inferView(from: Tree, to: Type)(implicit ctx: Context): SearchResult = track("inferView") {
401401
if ( (to isRef defn.AnyClass)
402402
|| (to isRef defn.ObjectClass)
403-
|| (to isRef defn.UnitClass)) NoImplicitMatches
403+
|| (to isRef defn.UnitClass)
404+
|| (from.tpe isRef defn.NothingClass)
405+
|| (from.tpe isRef defn.NullClass)) NoImplicitMatches
404406
else
405407
try inferImplicit(to.stripTypeVar.widenExpr, from, from.pos)
406408
catch {

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class tests extends CompilerTest {
108108
@Test def neg_boundspropagation = compileFile(negDir, "boundspropagation", xerrors = 4)
109109
@Test def neg_refinedSubtyping = compileFile(negDir, "refinedSubtyping", xerrors = 2)
110110
@Test def neg_i0248_inherit_refined = compileFile(negDir, "i0248-inherit-refined", xerrors = 4)
111+
@Test def neg_i0281 = compileFile(negDir, "i0281-null-primitive-conforms", xerrors = 3)
111112

112113
@Test def dotc = compileDir(dotcDir + "tools/dotc", twice)(allowDeepSubtypes)
113114
@Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast", twice)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object test {
2+
val b: scala.Boolean = null
3+
val c: Unit = null
4+
val d: Float = null
5+
val e: AnyVal = null
6+
}

0 commit comments

Comments
 (0)