Skip to content

Given conversion loosing type, when inlined #8276

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

Closed
edolgy opened this issue Feb 10, 2020 · 2 comments · Fixed by #12060
Closed

Given conversion loosing type, when inlined #8276

edolgy opened this issue Feb 10, 2020 · 2 comments · Fixed by #12060

Comments

@edolgy
Copy link

edolgy commented Feb 10, 2020

The code does not compile, but would compile if 'inline' is removed.

Introduced in 0.22, was fine in 0.21

object NOTHING

inline given [A]: Conversion[NOTHING.type, Option[A]] = _ => None

def apply[A](p: Vector[A], o: Option[A] = NOTHING): Unit = ???

apply[String](Vector.empty)
[error]  Found: Option[Any],  Required: Option[String]
@odersky
Copy link
Contributor

odersky commented Feb 12, 2020

It works fine if I give the default argument explicitly:

apply[String](Vector.empty, NOTHING)

There's a little too much going on here at the same time. To rely on an implicit conversion to make a default argument conform to the indicated type is a bit crazy. The problem might go away by itself if we redesign default arguments. Until then it's better to wait.

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Jun 12, 2020

Workaround

object NOTHING

inline given [A]: Conversion[NOTHING.type, Option[A]] = _ => None

def apply[A](p: Vector[A], o: Option[A] = NOTHING:  Option[A]): Unit = ???

def test = apply[String](Vector.empty)

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 12, 2021
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 13, 2021
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants