-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: simplify types before checking if implicit is underspecified #24659
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1668,15 +1668,14 @@ trait Implicits: | |
| def isUnderSpecifiedArgument(tp: Type): Boolean = | ||
| tp.isRef(defn.NothingClass) || tp.isRef(defn.NullClass) || (tp eq NoPrefix) | ||
|
|
||
| private def isUnderspecified(tp: Type): Boolean = tp.stripTypeVar match | ||
| private def isUnderspecified(tp: Type): Boolean = tp.simplified match | ||
| case tp: WildcardType => | ||
| !tp.optBounds.exists || isUnderspecified(tp.optBounds.hiBound) | ||
| case tp: ViewProto => | ||
| isUnderspecified(tp.resType) | ||
| || tp.resType.isRef(defn.UnitClass) | ||
| || isUnderSpecifiedArgument(tp.argType.widen) | ||
| case _ => | ||
| tp.isAny || tp.isAnyRef | ||
| case tp => tp.isAny || tp.isAnyRef || tp.isAnyVal | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a specification point of view, it would have been nice to check |
||
|
|
||
| /** Search implicit in context `ctxImplicits` or else in implicit scope | ||
| * of expected type if `ctxImplicits == null`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| -- [E007] Type Mismatch Error: tests/neg/i21304.scala:5:6 -------------------------------------------------------------- | ||
| 5 | foo(10) // error | ||
| | ^^ | ||
| | Found: (10 : Int) | ||
| | Required: AnyRef | Null | ||
| | Note that implicit conversions were not tried because the result of an implicit conversion | ||
| | must be more specific than AnyRef | Null | ||
| | | ||
| | One of the following imports might fix the problem: | ||
| | | ||
| | import scala.math.BigDecimal.int2bigDecimal | ||
| | import scala.math.BigInt.int2bigInt | ||
| | import scala.math.Numeric.IntIsIntegral.mkNumericOps | ||
| | import scala.math.Numeric.IntIsIntegral.mkOrderingOps | ||
| | import scala.math.Ordering.Int.mkOrderingOps | ||
| | import scala.math.Integral.Implicits.infixIntegralOps | ||
| | import scala.math.Ordered.orderingToOrdered | ||
| | import scala.math.Ordering.Implicits.infixOrderingOps | ||
| | import scala.math.Numeric.Implicits.infixNumericOps | ||
| | import scala.reflect.Selectable.reflectiveSelectable | ||
|
Comment on lines
+9
to
+20
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of them will ever help. An improvement would be to get rid of this list when we are underspecified. |
||
| | | ||
| | | ||
| | longer explanation available when compiling with `-explain` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| def foo(x: AnyRef | Null): Unit = | ||
| println(x) | ||
|
|
||
| @main def main(): Unit = | ||
| foo(10) // error |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- [E172] Type Error: tests/neg/implicits-numeric.scala:6:28 ----------------------------------------------------------- | ||
| 6 | println(implicitly[AnyVal]) // error | ||
| | ^ | ||
| | No implicit search was attempted for parameter e of method implicitly in object Predef | ||
| | since the expected type AnyVal is not specific enough |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,5 @@ object Test extends App { | |
| implicit def _1: Long = 1L | ||
| implicit def _2: Int = 0 | ||
|
|
||
| println(implicitly[AnyVal]) | ||
| println(implicitly[AnyVal]) // error | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test was completely bogus before, not only it should have been |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm willing to bet that we also need a dealiasing here.