diff options
-rw-r--r-- | src/dotty/tools/dotc/typer/Implicits.scala | 4 | ||||
-rw-r--r-- | test/dotc/tests.scala | 1 | ||||
-rw-r--r-- | tests/neg/i0281-null-primitive-conforms.scala | 6 |
3 files changed, 10 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index 90d1ceefb..82424164a 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -400,7 +400,9 @@ trait Implicits { self: Typer => def inferView(from: Tree, to: Type)(implicit ctx: Context): SearchResult = track("inferView") { if ( (to isRef defn.AnyClass) || (to isRef defn.ObjectClass) - || (to isRef defn.UnitClass)) NoImplicitMatches + || (to isRef defn.UnitClass) + || (from.tpe isRef defn.NothingClass) + || (from.tpe isRef defn.NullClass)) NoImplicitMatches else try inferImplicit(to.stripTypeVar.widenExpr, from, from.pos) catch { diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index f5072be96..4de8df8ad 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -108,6 +108,7 @@ class tests extends CompilerTest { @Test def neg_boundspropagation = compileFile(negDir, "boundspropagation", xerrors = 4) @Test def neg_refinedSubtyping = compileFile(negDir, "refinedSubtyping", xerrors = 2) @Test def neg_i0248_inherit_refined = compileFile(negDir, "i0248-inherit-refined", xerrors = 4) + @Test def neg_i0281 = compileFile(negDir, "i0281-null-primitive-conforms", xerrors = 3) @Test def dotc = compileDir(dotcDir + "tools/dotc", twice)(allowDeepSubtypes) @Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast", twice) diff --git a/tests/neg/i0281-null-primitive-conforms.scala b/tests/neg/i0281-null-primitive-conforms.scala new file mode 100644 index 000000000..469e72324 --- /dev/null +++ b/tests/neg/i0281-null-primitive-conforms.scala @@ -0,0 +1,6 @@ +object test { + val b: scala.Boolean = null + val c: Unit = null + val d: Float = null + val e: AnyVal = null +} |