forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SI-6899, prohibit dangerous, useless implicit conversions.
Increase eligibility requirements for implicit conversions, such that T => U is ineligible if T <: Null <or> AnyRef <: U This has the salutary effect of allowing us to ditch 16 ridiculous implicits from Predef, since they existed solely to work around the absence of this restriction. There was one tiny impact on actual source code (one line in one file) shown here, necessitated because the literal null is not eligible to be implicitly converted to A via <:<. def f[A](implicit ev: Null <:< A): A = null // before def f[A](implicit ev: Null <:< A): A = ev(null) // after As impositions go it's on the tame side.
- Loading branch information
Showing
8 changed files
with
54 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,7 @@ | ||
t4158.scala:3: error: type mismatch; | ||
found : Null(null) | ||
required: Int | ||
Note that implicit conversions are not applicable because they are ambiguous: | ||
both method Integer2intNullConflict in class LowPriorityImplicits of type (x: Null)Int | ||
and method Integer2int in object Predef of type (x: Integer)Int | ||
are possible conversion functions from Null(null) to Int | ||
t4158.scala:3: error: an expression of type Null is ineligible for implicit conversion | ||
var y = null: Int | ||
^ | ||
t4158.scala:2: error: type mismatch; | ||
found : Null(null) | ||
required: Int | ||
Note that implicit conversions are not applicable because they are ambiguous: | ||
both method Integer2intNullConflict in class LowPriorityImplicits of type (x: Null)Int | ||
and method Integer2int in object Predef of type (x: Integer)Int | ||
are possible conversion functions from Null(null) to Int | ||
t4158.scala:2: error: an expression of type Null is ineligible for implicit conversion | ||
var x: Int = null | ||
^ | ||
two errors found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
t6889.scala:16: error: the result type of an implicit conversion must be more specific than AnyRef | ||
def f(x: Dingo): AnyRef = x // fail - no conversion to AnyRef | ||
^ | ||
t6889.scala:17: error: an expression of type Null is ineligible for implicit conversion | ||
var x: Int = null // fail - no conversion from Null | ||
^ | ||
two errors found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package bippy { | ||
trait Bippy[A] extends Any | ||
} | ||
package foo { | ||
package object unrelated { | ||
implicit def bippyDingo[A](x: bippy.Bippy[A]): AnyRef = Nil | ||
} | ||
package unrelated { | ||
trait Unrelated | ||
} | ||
} | ||
|
||
object Test { | ||
trait Dingo extends Any with bippy.Bippy[foo.unrelated.Unrelated] | ||
|
||
def f(x: Dingo): AnyRef = x // fail - no conversion to AnyRef | ||
var x: Int = null // fail - no conversion from Null | ||
} |