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

Treat implicit by-name arguments as lazy values #1993

Merged
merged 3 commits into from
Feb 25, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 17, 2017

With the previous rules, the two test cases produce a
diverging implicit expansion. We avoid this by creating
for every implicit by-name argument of type T a lazy implicit
value of the same type. The implicit value is visible for all
nested implicit searches of by-name arguments. That way,
we tie the knot and obtain a recursive lazy value instead of
a diverging expansion.

@odersky
Copy link
Contributor Author

odersky commented Feb 17, 2017

@milessabin: I got this idea from our conversation at Scala.IO. Does it correspond to what you had in mind?

With the previous rules, the two test cases produce a
diverging implicit expansion. We avoid this by creating
for every implicit by-name argument of type T a lazy implicit
value of the same type. The implicit value is visible for all
nested implicit searches of by-name arguments. That way,
we tie the knot and obtain a recursive lazy value instead of
a diverging expansion.
@@ -537,27 +543,56 @@ trait Implicits { self: Typer =>
else EmptyTree
}

inferImplicit(formal, EmptyTree, pos) match {
/** The context to be used when resolving a by-name implicit argument.
* This makes any implicit stored under `DelayedIplicit` visible and
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: DelayedIplicit

}

/** formalValue: The value type for which an implicit is searched
* lazyIplicit: An implicit symbol to install for nested by-name resolutions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: lazyIplicit

@odersky odersky merged commit 8467e55 into scala:master Feb 25, 2017
@allanrenucci allanrenucci deleted the add-lazy-implicits branch December 14, 2017 16:57
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

Successfully merging this pull request may close these issues.

2 participants