Skip to content

Fix #6816: Deny methods with implicit members from tpd.applyOverloaded #6923

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

Merged
merged 1 commit into from
Aug 30, 2019

Conversation

anatoliykmetyuk
Copy link
Contributor

We cannot resolve implicit parameters outside Typer. Hence methods
that require implicit parameters should not be considered.

…loaded

We cannot resolve implicit parameters outside Typer. Hence methods
that require implicit parameters should not be considered.
@@ -1149,6 +1149,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
var allAlts = denot.alternatives
.map(denot => TermRef(receiver.tpe, denot.symbol))
.filter(tr => typeParamCount(tr) == targs.length)
.filter { _.widen match {
case MethodTpe(_, _, x: MethodType) => !x.isImplicitMethod
Copy link
Contributor

@odersky odersky Jul 31, 2019

Choose a reason for hiding this comment

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

What about curried methods that have implicit parameters as the 3rd parameter clause? Should we accept them? I guess there's no problem with those since we would not have to resolve them right away, right? If yes, it would be good to state this here as an explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There can be a problem... It looks like applyOverloaded resolves a method name looking only at the first argument group. E.g.:

def f(x: Int)(y: Int) given Z: Int
def f(x: String)(y: Int): Int
applyOverloaded("f", x: Any)

In both cases, the logic above infers x.isImplicitMethod to be false, so it cannot differentiate and can select the one with the implicit args at the end. Which it will never be able to call if we are after Typer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, OK. So we need to exclude all implicit methods, even of the implicit comes later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@odersky do you think this is no longer a problem?

@odersky odersky assigned anatoliykmetyuk and unassigned odersky Aug 2, 2019
@odersky odersky merged commit b5842bb into scala:master Aug 30, 2019
@odersky odersky deleted the i6816 branch August 30, 2019 14:19
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