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
mysterious companion scope allows erroneous code to compile #6668
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6668?orig=1 |
@retronym said: |
@paulp said: |
@harrah said: Implicit resolution first considers identifiers accessible without a prefix. It only moves on to the implicit scope (the companion object) if there are no eligible identifiers. If there are several eligible, overloading resolution applies. It does not appear to suggest that if that resolution is ambiguous, it continues to the implicit scope. Caveat: I didn't bother to grab the latest specification, so mine might be out of date. I'll update it tomorrow. |
@retronym said:
The spec seems very wrong: it tells me that the presence of any implicit in scope, e.g. any of those I get from The implementation looks like: def inferImplicit(tree: Tree, pt: Type, reportAmbiguous: Boolean, isView: Boolean, context: Context, saveAmbiguousDivergent: Boolean, pos: Position): SearchResult = {
...
var result = searchImplicit(context.implicitss, true)
if (result == SearchFailure) {
val previousErrs = context.flushAndReturnBuffer()
result = materializeImplicit(pt)
// `materializeImplicit` does some preprocessing for `pt`
// is it only meant for manifests/tags or we need to do the same for `implicitsOfExpectedType`?
if (result == SearchFailure) result = searchImplicit(implicitsOfExpectedType, false)
if (result == SearchFailure) {
context.updateBuffer(previousErrs)
}
}
} I'm going to seek a clerical interpretation on this one from Martin. At a minimum, the definition of "eligible" must be updated to "and conforms to the T". Then, we have to clarify what should happen when there is ambiguity. I'll track this under #6667. |
@harrah said: As a side note, the spec I have is actually the latest from the website, but the date on it is May 2011, so I thought there would be a more recent one. |
@paulp said: https://groups.google.com/d/msg/scala-language/E60_yrs_6lY/gE-jBH8tK0oJ |
Related to #6667, but not the same bug as far as I can see it. This is finding its idea of a non-ambiguous implicit A in the companion of A. The only problem with that is that A has no companion. Defining trait A outside of Test, or if Test is not an object, and it fails as expected.
The text was updated successfully, but these errors were encountered: