Skip to content

Fix #11299: Disallow implicit search on TermRef of Null #11312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -779,14 +779,15 @@ trait Implicits:
*/
def inferView(from: Tree, to: Type)(using Context): SearchResult = {
record("inferView")
val wfromtp = from.tpe.widen
if to.isAny
|| to.isAnyRef
|| to.isRef(defn.UnitClass)
|| from.tpe.isRef(defn.NothingClass)
|| from.tpe.isRef(defn.NullClass)
|| wfromtp.isRef(defn.NothingClass)
|| wfromtp.isRef(defn.NullClass)
|| !ctx.mode.is(Mode.ImplicitsEnabled)
|| from.isInstanceOf[Super]
|| (from.tpe eq NoPrefix)
|| (wfromtp eq NoPrefix)
then NoMatchingImplicitsFailure
else {
def adjust(to: Type) = to.stripTypeVar.widenExpr match {
Expand Down
10 changes: 10 additions & 0 deletions tests/neg/i11299.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
val myNull: Null = null

val n1: Int = null // error
val n2: Int = myNull // error

val b1: Boolean = null // error
val b2: Boolean = myNull // error

val v1: AnyVal = null // error
val v2: AnyVal = myNull // error