Skip to content
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

eta-expansion for method on target that needs implicit conversion #8299

Closed
scabug opened this issue Feb 17, 2014 · 4 comments · Fixed by scala/scala#6475
Closed

eta-expansion for method on target that needs implicit conversion #8299

scabug opened this issue Feb 17, 2014 · 4 comments · Fixed by scala/scala#6475
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Feb 17, 2014

object Test extends App {
  class C

  implicit class CompatibleC(c: C) {
    def foo(x: Int) = ???
  }

  val c: C = ???
  println(c.foo _)
}
15:44 ~/Projects/Master/sandbox (master)$ s
Test.scala:9: error: missing arguments for method foo in class CompatibleC;
follow this method with `_' if you want to treat it as a partially applied function
  println(c.foo _)
            ^
one error found

The error is the same if I manually create an implicit def.

@scabug
Copy link
Author

scabug commented Feb 17, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8299?orig=1
Reporter: @xeno-by
Affected Versions: 2.11.0-M8, 2.12.1

@scabug
Copy link
Author

scabug commented Feb 17, 2014

@adriaanm said:
Looks like an interaction with implicit conversion. Either convert the target first or annotate the argument type, you can't have both. Most likely a won't fix.

scala> lazy  val c: CompatibleC = ???
c: CompatibleC = <lazy>

scala>  println(c.foo _ )
<function1>

@scabug
Copy link
Author

scabug commented Feb 18, 2017

@som-snytt said:
The clever error message looks less clever:

scala> c.f _
<console>:14: error: missing argument list for method f in class CC
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `f _` or `f(_)` instead of `f`.
       c.f _
         ^

scala> c.f(_)
res3: Int => Int = $$Lambda$1088/149526537@e62319f

@scabug
Copy link
Author

scabug commented Mar 9, 2017

@som-snytt said:
Can anyone recommend a good beginner book for learning Scala?

Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> List(1,3,5).map("abc".isDefinedAt)
res0: List[Boolean] = List(true, false, false)

scala> List(1,3,5).map("abc".isDefinedAt _)
<console>:12: error: _ must follow method; cannot follow Int => Boolean
       List(1,3,5).map("abc".isDefinedAt _)
                             ^

scala> List(1,3,5).map("abc".isDefinedAt(_))
res2: List[Boolean] = List(true, false, false)

@scabug scabug added this to the Backlog milestone Apr 7, 2017
adriaanm added a commit to adriaanm/scala that referenced this issue Apr 11, 2018
We'll use the expected type when we type the eta-expansion
that was requested.

We know `m` is expected to be a method, since only methods
can be followed by `_` to request eta-expansion. So,
have the expected type reflect that. Since the original
expected type won't be compatible with the method type
that FUNmode gives us (method values are not first class),
we have to defer using the given expected type until we
eta-expanded, which results in a function, which is first class.

When typing under FUNmode under pt=* we can let implicit
conversion do its thing, before we wrap this in a function.

See scala/bug#8299.
adriaanm added a commit to adriaanm/scala that referenced this issue Apr 11, 2018
We'll use the expected type when we type the eta-expansion
that was requested.

We know `m` is expected to be a method, since only methods
can be followed by `_` to request eta-expansion. So,
have the expected type reflect that. Since the original
expected type won't be compatible with the method type
that FUNmode gives us (method values are not first class),
we have to defer using the given expected type until we
eta-expanded, which results in a function, which is first class.

When typing under FUNmode under pt=* we can let implicit
conversion do its thing, before we wrap this in a function.

See scala/bug#8299.
adriaanm added a commit to adriaanm/scala that referenced this issue Apr 11, 2018
We'll use the expected type when we type the eta-expansion
that was requested.

We know `m` is expected to be a method, since only methods
can be followed by `_` to request eta-expansion. So,
have the expected type reflect that. Since the original
expected type won't be compatible with the method type
that FUNmode gives us (method values are not first class),
we have to defer using the given expected type until we
eta-expanded, which results in a function, which is first class.

When typing under FUNmode under pt=* we can let implicit
conversion do its thing, before we wrap this in a function.

See scala/bug#8299.
adriaanm added a commit to adriaanm/scala that referenced this issue Apr 26, 2018
We'll use the expected type when we type the eta-expansion
that was requested.

We know `m` is expected to be a method, since only methods
can be followed by `_` to request eta-expansion. So,
have the expected type reflect that. Since the original
expected type won't be compatible with the method type
that FUNmode gives us (method values are not first class),
we have to defer using the given expected type until we
eta-expanded, which results in a function, which is first class.

When typing under FUNmode under pt=* we can let implicit
conversion do its thing, before we wrap this in a function.

See scala/bug#8299.
adriaanm added a commit to adriaanm/scala that referenced this issue Apr 26, 2018
We'll use the expected type when we type the eta-expansion
that was requested.

We know `m` is expected to be a method, since only methods
can be followed by `_` to request eta-expansion. So,
have the expected type reflect that. Since the original
expected type won't be compatible with the method type
that FUNmode gives us (method values are not first class),
we have to defer using the given expected type until we
eta-expanded, which results in a function, which is first class.

When typing under FUNmode under pt=* we can let implicit
conversion do its thing, before we wrap this in a function.

See scala/bug#8299.
adriaanm added a commit to adriaanm/scala that referenced this issue May 8, 2018
We'll use the expected type when we type the eta-expansion
that was requested.

We know `m` is expected to be a method, since only methods
can be followed by `_` to request eta-expansion. So,
have the expected type reflect that. Since the original
expected type won't be compatible with the method type
that FUNmode gives us (method values are not first class),
we have to defer using the given expected type until we
eta-expanded, which results in a function, which is first class.

When typing under FUNmode under pt=* we can let implicit
conversion do its thing, before we wrap this in a function.

See scala/bug#8299.
lrytz pushed a commit to adriaanm/scala that referenced this issue May 10, 2018
We'll use the expected type when we type the eta-expansion
that was requested.

We know `m` is expected to be a method, since only methods
can be followed by `_` to request eta-expansion. So,
have the expected type reflect that. Since the original
expected type won't be compatible with the method type
that FUNmode gives us (method values are not first class),
we have to defer using the given expected type until we
eta-expanded, which results in a function, which is first class.

When typing under FUNmode under pt=* we can let implicit
conversion do its thing, before we wrap this in a function.

See scala/bug#8299.
@SethTisue SethTisue modified the milestones: Backlog, 2.13.0-M4 May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants