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

Compatibility with implicit resolution #31

Open
acjay opened this issue May 9, 2017 · 1 comment
Open

Compatibility with implicit resolution #31

acjay opened this issue May 9, 2017 · 1 comment

Comments

@acjay
Copy link

acjay commented May 9, 2017

I'm trying to capture the literal floating-point number that a person used in a data structure:

scala> trait Capture { def text: String }
defined trait Capture

scala> implicit class DoubleCapture(source: sourcecode.Text[Double]) extends Capture { def text = source.source }
defined class DoubleCapture
                    ^

scala> val x: Capture = 5.0
<console>:49: error: type mismatch;
 found   : Double(5.0)
 required: Capture
       val x: Capture = 5.0

If DoubleCapture takes a Double, this works fine. But I don't want the Double itself, what I really want is the string representation from the code itself. I was hoping I could use sourcecode.Text to do this, but it doesn't seem to work.

@lihaoyi
Copy link
Member

lihaoyi commented Aug 11, 2017

Implicit conversions are, unfortunately, not chainable. I don't know of any way around that in this case. The normal solution of

implicit class DoubleCapture[T](source: T)(implicit f: T => sourcecode.Text[Double])

Doesn't work in this case, because we need the sourcecode.Text(...) wrapped to lexically wrap the expression that we are being given.

If anyone has any ideas I'd love to hear them, but otherwise I don't know if/how/when we can fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants