-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Value + is not a member of Int #10082
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
Comments
The following works: object Kotlin:
class Ctx[T](val x: T) extends AnyVal
def fun[T, U](fn: Ctx[T] ?=> U): T => U = (x: T) => fn(using new Ctx(x))
def it[T](using ctx: Ctx[T]) = ctx.x
import Kotlin._
@main def Test =
val res = List(1).map(fun(it + 1))
assert(res == List(2)) |
The reason is that from the program we only know that |
Thank you, it worked. |
We do need to improve the error message. I'll make another PR to fix that. |
The type `site` might be an uninitialized type variable, but is initialized when we display the error message. It results in confusing error message as in scala#10082. We take a string representation of the type `site` when the error object is created and use that in the message message. Now the error message is more sensible: -- [E008] Not Found Error: tests/neg/i10082.scala:7:30 ------------------------- 7 |def Test = List(1).map(fun(it + 1)) | ^^^^ | value + is not a member of T | | where: T is a type variable with constraint >: Int | , but could be made available as an extension method.
The type `site` in class `NotAMember` might be an uninitialized type variable, but is initialized when we display the error message. It results in confusing error message as in scala#10082. We avoid instantiating the type variable when there is a unreported error in current typerstate.
The type `site` in class `NotAMember` might be an uninitialized type variable, but is initialized when we display the error message. It results in confusing error message as in scala#10082. We avoid instantiating the type variable when there is a unreported error in current typerstate.
Fix #10082: show friendly error message related to type inference
scala#10082 now compiles as well. The original test was about a confusing error message.
scala#10082 now compiles as well. The original test was about a confusing error message.
scala#10082 now compiles as well. The original test was about a confusing error message.
Inspired by Context Functions, I decided to practice my bad taste on simulating the
it
anonymous function parameter. But it doesn't work.Minimized code
Output
Expectation
This code should compile as
it
has already been inferred asInt
.Workaround
Providing type arguments to
fun
works.The text was updated successfully, but these errors were encountered: