summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
Commit message (Collapse)AuthorAgeFilesLines
* Fix Greek Mythology references in compiler packageJanek Bogucki2017-04-101-3/+3
| | | | | | | Improve documentation some packages and correct some typos in these directories, - compiler - library
* Merge 2.11.x into 2.12.xAdriaan Moors2017-04-071-19/+22
|\ | | | | | | Include 99f41a1 Merge pull request #5736
| * SI-10206 tighten fix for SI-6889Adriaan Moors2017-02-231-19/+22
| | | | | | | | | | There are more supertypes of `AnyRef` than you might think: `?{def clone: ?}` is one example...
* | Make ImplicitInfo hashCode consistent with equals.Miles Sabin2017-04-031-1/+4
| |
* | Refactor flag juggling. Review feedback from Jason.Adriaan Moors2016-03-261-8/+5
| | | | | | | | Sometimes booleans and a little duplication go a long way.
* | Refactoring. Simplify inferImplicit's boolean leversAdriaan Moors2016-03-261-6/+33
| |
* | Remove unused imports and other minor cleanupsSimon Ochsenreither2015-12-181-1/+1
| | | | | | | | | | | | | | | | | | | | - Language imports are preceding other imports - Deleted empty file: InlineErasure - Removed some unused private[parallel] methods in scala/collection/parallel/package.scala This removes hundreds of warnings when compiling with "-Xlint -Ywarn-dead-code -Ywarn-unused -Ywarn-unused-import".
* | Merge commit '8eb1d4c' into merge-2.11-to-2.12-nov-24Lukas Rytz2015-11-241-3/+3
|\|
| * it's Scaladoc, not "ScalaDoc" or "Scala doc"Seth Tisue2015-11-121-3/+3
| | | | | | | | | | renaming the existing ScalaDoc and ScalaDocReporter classes might break stuff, sadly, but at least we can fix the rest
* | Merge commit '03aaf05' into merge-2.11-to-2.12-sep-22Lukas Rytz2015-09-221-1/+1
|\|
| * SI-4438 FindAll implicits after errorJason Zaugg2015-09-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix cross talk between candidates in ImplicitComputation#findAll. Haoyi reported that he couldn't get the presentation compiler to offer completion suggestions for extension methods on primitive arrays. Turns out that an error in typechecking the previous candidate had not been cleared, and this was taken to mean that `arrayIntOps` was itself ineligible. After this patch: ``` scala> Array(1, 2, 3) reverse reverseIterator reverse reverseMap reversed scala> Array(1,2,3).reverse //print scala.Predef.intArrayOps(scala.Array.apply(1, 2, 3)).reverse scala> Array(1, 2, 3) to toString toCollection toSeq toIterator to toMap toSet toList toArray toBuffer toStream toIterable toTraversable toVector toIndexedSeq scala> Array(1, 2, 3) toSeq override def toSeq: Seq[Int] ```
* | Merge pull request #4673 from puffnfresh/issue/6806Jason Zaugg2015-09-081-35/+39
|\ \ | | | | | | SI-6806 Add an @implicitAmbiguous annotation
| * | SI-6806 Add an @implicitAmbiguous annotationBrian McKenna2015-08-111-35/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Example usage: trait =!=[C, D] implicit def neq[E, F] : E =!= F = null @annotation.implicitAmbiguous("Could not prove ${J} =!= ${J}") implicit def neqAmbig1[G, H, J] : J =!= J = null implicit def neqAmbig2[I] : I =!= I = null implicitly[Int =!= Int] Which gives the following error: implicit-ambiguous.scala:9: error: Could not prove Int =!= Int implicitly[Int =!= Int] ^ Better than what was previously given: implicit-ambiguous.scala:9: error: ambiguous implicit values: both method neqAmbig1 in object Test of type [G, H, J]=> Main.$anon.Test.=!=[J,J] and method neqAmbig2 in object Test of type [I]=> Main.$anon.Test.=!=[I,I] match expected type Main.$anon.Test.=!=[Int,Int] implicitly[Int =!= Int] ^
* | | Merge remote-tracking branch 'origin/2.11.x' into 2.12.xSeth Tisue2015-08-201-6/+8
|\ \ \ | |/ / |/| / | |/ | | | | | | | | | | | | all conflicts were because the changes changed code that doesn't exist anymore in 2.12; they were resolved with `git checkout --ours` c201eac changed bincompat-forward.whitelist.conf but I dropped the change in this merge because it refers to AbstractPromise which no longer exists in 2.12
| * Merge pull request #4688 from retronym/topic/typer-debug-implicitsLukas Rytz2015-08-101-2/+4
| |\ | | | | | | Fix tracing of implicit search under -Ytyper-debug
| | * Fix tracing of implicit search under -Ytyper-debugJason Zaugg2015-08-061-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The log messages intented to chronicle implicit search were always being filtered out by virtue of the fact that the the tree passed to `printTyping` was already typed, (e.g. with an implicit MethodType.) This commit enabled printing in this case, although it still filters out trees that are deemed unfit for typer tracing, such as `()`. In the context of implicit search, this happens to filter out the noise of: ``` | | | [search #2] start `()`, searching for adaptation to pt=Unit => Foo[Int,Int] (silent: value <local Test> in Test) implicits disabled | | | [search #3] start `()`, searching for adaptation to pt=(=> Unit) => Foo[Int,Int] (silent: value <local Test> in Test) implicits disabled | | | \-> <error> ``` ... which I think is desirable. The motivation for this fix was to better display the interaction between implicit search and type inference. For instance: ``` class Foo[A, B] class Test { implicit val f: Foo[Int, String] = ??? def t[A, B](a: A)(implicit f: Foo[A, B]) = ??? t(1) } ``` ```` % scalac -Ytyper-debug sandbox/instantiate.scala ... | |-- t(1) BYVALmode-EXPRmode (site: value <local Test> in Test) | | |-- t BYVALmode-EXPRmode-FUNmode-POLYmode (silent: value <local Test> in Test) | | | [adapt] [A, B](a: A)(implicit f: Foo[A,B])Nothing adapted to [A, B](a: A)(implicit f: Foo[A,B])Nothing | | | \-> (a: A)(implicit f: Foo[A,B])Nothing | | |-- 1 BYVALmode-EXPRmode-POLYmode (site: value <local Test> in Test) | | | \-> Int(1) | | solving for (A: ?A, B: ?B) | | solving for (B: ?B) | | [search #1] start `[A, B](a: A)(implicit f: Foo[A,B])Nothing` inferring type B, searching for adaptation to pt=Foo[Int,B] (silent: value <local Test> in Test) implicits disabled | | [search #1] considering f | | [adapt] f adapted to => Foo[Int,String] based on pt Foo[Int,B] | | [search #1] solve tvars=?B, tvars.constr= >: String <: String | | solving for (B: ?B) | | [search #1] success inferred value of type Foo[Int,=?String] is SearchResult(Test.this.f, TreeTypeSubstituter(List(type B),List(String))) | | |-- [A, B](a: A)(implicit f: Foo[A,B])Nothing BYVALmode-EXPRmode (site: value <local Test> in Test) | | | \-> Nothing | | [adapt] [A, B](a: A)(implicit f: Foo[A,B])Nothing adapted to [A, B](a: A)(implicit f: Foo[A,B])Nothing | | \-> Nothing ```
| * | ScalaDoc fixes for compilerJanek Bogucki2015-07-291-4/+4
| |/
* | Merge remote-tracking branch 'origin/2.11.x' into ↵Jason Zaugg2015-07-231-2/+2
|\| | | | | | | merge/2.11.x-to-2.12.x-20152307
| * Fix typo in val nameJanek Bogucki2015-07-171-2/+2
| |
* | Merge pull request #4616 from som-snytt/issue/9383Seth Tisue2015-07-201-1/+1
|\ \ | | | | | | SI-9383 Improved unused import warning
| * | SI-9383 Improved unused import warningSom Snytt2015-07-081-1/+1
| | | | | | | | | | | | | | | | | | | | | Previously, implicit search would mark every import it touched as a lookup. Instead, let subsequent type check perform the lookup.
* | | Merge remote-tracking branch 'origin/2.11.x' into ↵Jason Zaugg2015-07-131-1/+1
|\ \ \ | |/ / |/| / | |/ | | | | | | | | | | | | | | | | | | merge/2.11.x-to-2.12.x-20150713 Conflicts: src/eclipse/partest/.classpath src/eclipse/repl/.classpath test/files/run/nothingTypeNoFramesNoDce.scala test/files/run/repl-javap-app.check Also fixup two .classpath files with updated partest, xml and parser combinators JARs.
| * Fix 25 typos (s)Janek Bogucki2015-07-061-1/+1
| |
* | Merge branch '2.11.x' into merge/2.11.x-to-2.12.x-20150624Jason Zaugg2015-06-241-1/+1
|\|
| * Fix 25 typos (g-i)Janek Bogucki2015-06-221-1/+1
| |
* | Merge commit '32f520f' into merge/2.11-to-2.12-apr-1Lukas Rytz2015-04-011-2/+2
|\|
| * Removed warningsEECOLOR2015-03-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Added `since` to deprecation statement - Added unit to parameter list - Removed usage of deprecated method polyType - Replaced deprecated `debugwarn` with `devWarning` - Changed switch statement to if else in order to remove a warning - Switched implementation of `init` and `processOptions` to prevent warning - Replaced deprecated `Console.readLine` with `scala.io.StdIn.readLine` - Replaced deprecated `startOrPoint` with `start` - Replaced deprecated `tpe_=` with `setType` - Replaced deprecated `typeCheck` with `typecheck` - Replaced deprecated `CompilationUnit.warning` with `typer.context.warning` - Replaced deprecated `scala.tools.nsc.util.ScalaClassLoader` with `scala.reflect.internal.util.ScalaClassLoader` - Replaced deprecated `scala.tools.ListOfNil` with `scala.reflect.internal.util.ListOfNil` - Replaced deprecated `scala.tools.utils.ScalaClassLoader` with `scala.reflect.internal.util.ScalaClassLoader` - Replaced deprecated `emptyValDef` with `noSelfType` - In `BoxesRunTime` removed unused method and commented out unused values. Did not delete to keep a reference to the values. If they are deleted people might wonder why `1` and `2` are not used. - Replaced deprecated `scala.tools.nsc.util.AbstractFileClassLoader` with `scala.reflect.internal.util.AbstractFileClassLoader`
| * new{Term,Type}Name→{Term,Type}Name, tpename/nme→{type,term}NamesSimon Ochsenreither2015-03-261-1/+1
| |
* | Merge commit 'fcc20fe' into merge/2.11-to-2.12-apr-1Lukas Rytz2015-04-011-3/+3
|\|
| * SI-9153 More complete and stable results for completionsJason Zaugg2015-02-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Three items of background are needed to understand this bug. 1. When typechecking an application like `qual.m({stats; expr})`, the argument is typechecked using the formal parameter type of `m` as the expected type. If this fails with a type error located within in `expr`, the typer instead re-typechecks under `ContextMode.ReTyping` without an expected type, and then searches for an implicit adaptation to enable `view(qual).m(args)`. Under this mode, `Typer#typed1` clears the type of incoming trees. 2. The presentation compiler performs targetted operations like type completions by: - typechecking the enclosing tree, registering all typechecker `Context`s created in the process (`registerContext`) - finding the smallest enclosing `Context` around the target position (`doLocateContext`) - Using this context to perform implicit search, which can contribute members to the completion. (`applicableViews` within `interactive.Global#typeMembers`) 3. When verifiying whether or not a candidate implicit is applicable as a view from `F => T`, implicit search typechecks a dummy call of the form `q"candiate(${Ident("<argument>").setType(typeOf[F])})". Now, picture yourself at the nexus of these three storms. In the enclosed test case, we search for completions at: x + 1.<caret> 1. Because the code is incomplete, the application of `Int#+` doesn't typecheck, and the typer also tries to adapt `x` to a method applicable to the re-typechecked argument. 2. This process registers a context with `retypechecking` set to true. (If multiple contexts at the same position are registered, the last one wins.) 3. Implicit search uses this context to typecheck `Predef.Ensuring(<argument>.setType(Int))`, but the argument is promptly stripped of its type and retypechecking fails as there is no definition named `<argument>` in scope. As such, we missed out on extension methods, like `ensuring` in the list of completions. This commit changes the presentation compiler to turn off retyping mode in the context before starting to work with it. (Are the other modes that might cause similar bugs?) Once I made that change, I noticed that the results the enclosed test was not stable. I tracked this down to the use of a `HashMap` to carry the applicable implicit views, together with the way that the presentation compiler removes duplicates. This commit switched to a `LinkedHashMap`.
| * Cache name for dummy argument used in implicit searchJason Zaugg2015-02-171-1/+1
| | | | | | | | | | | | This avoids a minor inefficiency of interning the name on each implicit candidate. Instead, we follow the usual practice and use a pre-baked name from `StdNames`.
* | Merge remote-tracking branch 'origin/2.11.x' into ↵Jason Zaugg2015-01-291-2/+2
|\| | | | | | | | | | | | | | | | | merge/2.11.x-to-2.12.x-20150129 Conflicts: build.number src/library/scala/concurrent/Future.scala versions.properties
| * Fix many typos in docs and commentsmpociecha2014-12-141-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | This commit corrects many typos found in scaladocs, comments and documentation. It should reduce a bit number of PRs which fix one typo. There are no changes in the 'real' code except one corrected name of a JUnit test method and some error messages in exceptions. In the case of typos in other method or field names etc., I just skipped them. Obviously this commit doesn't fix all existing typos. I just generated in IntelliJ the list of potential typos and looked through it quickly.
* | Merge commit 'eb15950' into merge/2.11.x-to-2.12.x-20150129Jason Zaugg2015-01-291-1/+3
|\|
| * SI-8291 Fix implicitNotFound message with type aliasesJason Zaugg2014-10-051-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This pattern of code is typically a bug: if (f(tp.typeSymbol)) { g(tp.typeArgs) } Intead, one needs to take the base type of `tp` wrt `tp.typeSymbol`. This commit does exactly that when formatting the `@implicitNotFound` custom error message. Patch found on the back of an envelope in the handwriting of @adriaanm
* | More uniform treatment of package objectsJason Zaugg2014-11-071-12/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Introduce `Symbol#packageObject` and `Type#packageObject` to lookup the member package object of a package class/module, and use this far and wide. - Replace the overly complicated (and still buggy) implementation of `Context#isInPackageObject` with a one liner. The simplifying insight is that if we select a symbol from a package prefix that does not own that symbol, it *must* have really been selected from the package object. - Change implicit search to use the cache in `ModuleSymbol#implicitMembers` via `Type#implicitMembers`, which lets the client code read more naturally. Fixes a bug with `adapt::insertApply` that Adriaan spotted in a feat of lateral thinking. This is tested in t8862b.scala. alladin763.scala adds the test case from the bug originally remedied by `insertApply` to check we haven't regressed.
* | SI-8862 Fix treatment of inherited implicits in package objectsJason Zaugg2014-11-071-2/+5
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Two spots in implicit search fell prey to a trap with package objects. Members of a package object are entered into the scope of the enclosing package, but that doesn't form a suitable prefix for determing the member type. A REPL transcript paints a picture that speaks a 1000 words: ``` scala> :paste -raw // Entering paste mode (ctrl-D to finish) package p { class C[A] { def foo: A = ??? }; object `package` extends C[String] } // Exiting paste mode, now interpreting. scala> val p = rootMirror.getPackageIfDefined("p") warning: there was one deprecation warning; re-run with -deprecation for details p: $r.intp.global.Symbol = package p scala> p.info.decls res0: $r.intp.global.Scope = Scopes(class C, package object p, method foo) scala> val foo = p.info.decl(TermName("foo")) foo: $r.intp.global.Symbol = method foo scala> p.typeOfThis memberType foo res1: $r.intp.global.Type = => A scala> val fooOwner = foo.owner fooOwner: $r.intp.global.Symbol = class C scala> p.info.decl(nme.PACKAGE).typeOfThis memberType foo res3: $r.intp.global.Type = => String ``` This commit detects if we find an implicit in a package module, and then uses the self type of the corresponding package object as the prefix for the `ImplicitInfo`. This is done in both `Context.implicitss` (which collects in-scope implicits), and in `companionImplicitMap` (which harvests them from the implicit scope.) In addition, it was necessary / possible to remove a special case that excluded package object implicits, the referenced tests for SI-3999 now pass without this.
* Separate statistics from functional code; optimize.Adriaan Moors2014-08-041-32/+45
|
* Towards more privacy for _reporter.Adriaan Moors2014-08-041-7/+4
| | | | | | | | | | | | | | | | | | | Move code that manipulates the error buffers / reporters into combinators in Context/ContextReporter. Eventually, would like to statically know when we're in silent mode, and only then use buffering (push buffering code down to BufferingReporter). Simplify TryTwice; avoid capturing mutable var in closure. Changed inSilentMode to no longer check `&& !reporter.hasErrors`; disassembling optimized code showed that this was keeping the inliner from inlining this method. Introduce a couple more combinators: - withFreshErrorBuffer - propagatingErrorsTo - propagateImplicitTypeErrorsTo
* s/reportBuffer/reporterAdriaan Moors2014-07-181-16/+16
|
* Encapsulate reporting mode as class of reportBuffer.Adriaan Moors2014-07-181-5/+6
| | | | | | | | | | | | Reporting mode used to be governed by contextMode. This logic is left in place by this commit, and the consistency of the new and the old is checked. Will be removed in follow-up commit. The main difference is that we no longer throw TypeErrors in buffering mode. There was one instance of context.error in implicit search the exploited the fact that implicit search runs in buffering (silent) mode and thus calls to error(pos,msg) used to throw new TypeError(pos, msg) -- made this explicit, and removed throwing behavior from the buffering context reporter.
* Reduce Context iface: encapsulate buffer manipulation.Adriaan Moors2014-07-171-4/+1
|
* Reduce Context iface: inline complex forwarders.Adriaan Moors2014-07-171-5/+5
|
* Reduce Context iface: inline trivial forwarders.Adriaan Moors2014-07-171-10/+10
| | | | | | | The overarching goal is to route all contextual reporting through a single entry point: `context.reporter`. The following commits take baby steps towards this goal.
* Clarify divergentError commentAdriaan Moors2014-07-171-1/+2
|
* Simplify (ambiguous) error issuing.Adriaan Moors2014-07-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | The two functional differences are: - always add the diagnostics string - check erroneousness in `issueAmbiguousTypeErrorUnlessErroneous`, before even constructing the error message. Consider this nugget: ``` - def issueAmbiguousError(pre: Type, sym1: Symbol, sym2: Symbol, err: AbsTypeError) { - issueCommon(err) { case _ if ambiguousErrors => - if (!pre.isErroneous && !sym1.isErroneous && !sym2.isErroneous) ``` I'd like to state for the record that the if-erroneous in the case of the partial function looked super-dodgy: it meant that, when `ambiguousErrors`, `issueCommon` would not get to the `else` branches that buffer or throw, and if the erroneous condition was met, nothing would be issued/buffered/thrown. This refactoring checks this condition up front.
* SI-8617 Avoid rangepos crash for OptManifest materializerJason Zaugg2014-05-241-1/+1
| | | | The tree to create a `NoManifest` was unpositioned.
* Refactor rankImplicits, add some more docsAdriaan Moors2014-04-011-24/+26
|
* Refactor: keep DivergentImplicitRecovery logic together.Adriaan Moors2014-04-011-12/+12
|
* SI-8460 Fix regression in divergent implicit recoveryJason Zaugg2014-03-311-4/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implicit search detects likely cycles by looking at the stack of open implicits and checking the same implicit appears twice, and if the second occurrence is trying satisfy an implicit search for a "dominant" type. Originally, this condition immediately failed the entire implicit search. However, since Scala 2.10, this mechanism has been refined to continue searching after the first divergent implicit is detected. If a second divergence is found, we fail immediately. If the followup search fails, we report the first divergence. Otherwise, we take the successful result. This mechanism was originally built around exceptions. This proved to be fragile, and was refactored in SI-7291 / accaa314 to instead use the `Context.errors` to control the process. But, since that change, the pattern of implicits in scalanlp/breeze and Shapeless have been prone to reporting the divergent implicit errors where they used to recover. So long as we left the `DivergentImplictTypeError` that originates from a nested implicit search in `context.errors`, we are unable to successfully typecheck other candidates. This commit instead stashes the first such error away in `DivergentImplicitRecovery`, to clear the way for the alternative path to succeed. We must retain any other divergent implicit errors, as witnessed by test/files/neg/t2031.scala, which loops unless we retain divergent implicit errors that we don't stash in `DivergentImplicitRecovery`.