-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Take into account the result type of inline implicit conversions unless they are transparent #17924
Take into account the result type of inline implicit conversions unless they are transparent #17924
Conversation
72bfe2b
to
1e7bf82
Compare
| | ||
| The following import might make progress towards fixing the problem: | ||
| | ||
| import foo.Baz.toBaz |
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.
Note that only the transparent inline conversion is suggested.
* In that case, we should always succeed and not constrain type parameters in the expected type, | ||
* because the actual return type can be a subtype of the currently known return type. | ||
* However, we should constrain parameters of the declared return type. This distinction is | ||
* achieved by replacing expected type parameters with wildcards. | ||
*/ | ||
def constrainResult(meth: Symbol, mt: Type, pt: Type)(using Context): Boolean = | ||
if (Inlines.isInlineable(meth)) { | ||
if (Inlines.isInlineable(meth) && meth.is(Transparent)) { |
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 am not 100% this is the right place to perform this test. Please let me know if there is a more appropriate place that contains more logic related to transparent definitions.
This comment was marked as resolved.
This comment was marked as resolved.
…ompiler Currently, the compiler incorrectly reports errors like: ~~~ text [error] val n: Int = 0; val s: Int = n + "hello" [error] ^ [error] Found: String [error] Required: Int [error] [error] One of the following imports might make progress towards fixing the problem: [error] [error] import org.specs2.io.FileName.ToFileName [error] import org.specs2.TimeoutSpecExample.asExecutionIsInterpolated [error] import org.specs2.reflect.FromObjectName.asExecutionIsInterpolated [error] import org.specs2.reporter.reporterSpecSupport.asExecutionIsInterpolated [error] import org.specs2.runner.RunnerSpecification.asExecutionIsInterpolated [error] import org.specs2.specification.S1.asExecutionIsInterpolated [error] import org.specs2.specification.S2.asExecutionIsInterpolated [error] import org.specs2.specification.dsl1.asExecutionIsInterpolated [error] import org.specs2.TimeoutSpecExample.asResultIsInterpolated [error] import org.specs2.reflect.FromObjectName.asResultIsInterpolated ~~~ But after scala/scala3#17924 is merged, the import suggestions will be removed from the output. We adjust the test specification in TypecheckSpec to pass both with the current compiler and with the fix in the linked PR.
…ompiler (#1165) Currently, the compiler incorrectly reports errors like: ~~~ text [error] val n: Int = 0; val s: Int = n + "hello" [error] ^ [error] Found: String [error] Required: Int [error] [error] One of the following imports might make progress towards fixing the problem: [error] [error] import org.specs2.io.FileName.ToFileName [error] import org.specs2.TimeoutSpecExample.asExecutionIsInterpolated [error] import org.specs2.reflect.FromObjectName.asExecutionIsInterpolated [error] import org.specs2.reporter.reporterSpecSupport.asExecutionIsInterpolated [error] import org.specs2.runner.RunnerSpecification.asExecutionIsInterpolated [error] import org.specs2.specification.S1.asExecutionIsInterpolated [error] import org.specs2.specification.S2.asExecutionIsInterpolated [error] import org.specs2.specification.dsl1.asExecutionIsInterpolated [error] import org.specs2.TimeoutSpecExample.asResultIsInterpolated [error] import org.specs2.reflect.FromObjectName.asResultIsInterpolated ~~~ But after scala/scala3#17924 is merged, the import suggestions will be removed from the output. We adjust the test specification in TypecheckSpec to pass both with the current compiler and with the fix in the linked PR.
…ompiler (etorreborre#1165) Currently, the compiler incorrectly reports errors like: ~~~ text [error] val n: Int = 0; val s: Int = n + "hello" [error] ^ [error] Found: String [error] Required: Int [error] [error] One of the following imports might make progress towards fixing the problem: [error] [error] import org.specs2.io.FileName.ToFileName [error] import org.specs2.TimeoutSpecExample.asExecutionIsInterpolated [error] import org.specs2.reflect.FromObjectName.asExecutionIsInterpolated [error] import org.specs2.reporter.reporterSpecSupport.asExecutionIsInterpolated [error] import org.specs2.runner.RunnerSpecification.asExecutionIsInterpolated [error] import org.specs2.specification.S1.asExecutionIsInterpolated [error] import org.specs2.specification.S2.asExecutionIsInterpolated [error] import org.specs2.specification.dsl1.asExecutionIsInterpolated [error] import org.specs2.TimeoutSpecExample.asResultIsInterpolated [error] import org.specs2.reflect.FromObjectName.asResultIsInterpolated ~~~ But after scala/scala3#17924 is merged, the import suggestions will be removed from the output. We adjust the test specification in TypecheckSpec to pass both with the current compiler and with the fix in the linked PR.
0d7b97d
to
67c6a55
Compare
The CI is green and the PR is ready for review. |
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.
@julienrf could you squash the commits before we merge this?
…ss they are transparent Fixes scala#9685
67c6a55
to
eb38e1f
Compare
Thank you for the review. I squashed the commits. |
Did this work in 3.3.0? If not, we do not necessarily need to backport this and may wait until 3.3.2. |
No, the bug was present since 3.0.0. |
We apply the full fix under `-source future` only, and a partial fix otherwise. This is a followup of scala#17924 that fixes the source incompatibilities reported in scala#18130. We test that the behavior under `-source future` still fixes scala#9685, and that without `-source future` we fix both scala#9685 and scala#18130.
We apply the full fix under `-source future` only, and a partial fix otherwise. This is a followup of scala#17924 that fixes the source incompatibilities reported in scala#18123. We test that the behavior under `-source future` still fixes scala#9685, and that without `-source future` we fix both scala#9685 and scala#18123.
We apply the full fix under `-source future` only, and a partial fix otherwise. This is a followup of scala#17924 that fixes the source incompatibilities reported in scala#18123. We test that the behavior under `-source future` still fixes scala#9685, and that without `-source future` we fix both scala#9685 and scala#18123.
We apply the full fix under `-source future` only, and a partial fix otherwise. This is a followup of scala#17924 that fixes the source incompatibilities reported in scala#18123. We test that the behavior under `-source future` still fixes scala#9685, and that without `-source future` we fix both scala#9685 and scala#18123.
In the first commit, I add a failing test:
We expect that code to not compile but the error reported by the compiler is confusing as it suggests importing
Foo.toFoo
to resolve the compilation error. You can see this in the test report.The problem comes from the fact that currently when the compiler checks whether an implicit conversion is applicable to an expression that fails to compile, it does not take into account the expected result type (here,
? { def asdf: ? }
) if the candidate is aninline
definition.Instead, I believe the expected result type should be taken into account unless the candidate is a
transparent inline
. I make this change in the second commit, which makes the test pass.Fixes #9685