summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Commit message (Collapse)AuthorAgeFilesLines
* SI-9839 Avoid crash in macro import selector posSom Snytt2017-03-111-6/+4
| | | | | | Ignore bad name pos. Also delete unused val. Thanks, `-Ywarn-unused`!
* Merge pull request #5622 from edmundnoble/extra-errsAdriaan Moors2017-03-021-1/+1
|\ | | | | Improved error messages for identically named, differently prefixed types
| * Improved error messages for identically named, differently prefixed typesEdmund Noble2016-12-311-1/+1
| |
* | Merge pull request #5700 from retronym/ticket/10154-refactorLukas Rytz2017-02-211-17/+23
|\ \ | | | | | | Refactor lookupCompanion
| * | Refactor implementation of lookupCompanionJason Zaugg2017-02-191-17/+23
| | | | | | | | | | | | | | | - Check for module class up front to use sourceModule - Consolidate most of the logic in Contexts
* | | Merge pull request #5640 from optimizely/repl-import-handlerAdriaan Moors2017-02-201-2/+5
|\ \ \ | |/ / |/| | SI-9881 Fix ImportHandler's reporting of importedNames and importedSymbols
| * | Fix ImportHandler's reporting of importedNames and importedSymbolsHao Xia2017-01-111-2/+5
| |/
* / SI-10154 Fix implicit search regression for term-owned objectsJason Zaugg2017-01-201-1/+2
|/ | | | | | | | | | | | | | | | | | | A recent change to fix lookup of companion implicits of term-owned classes (#5550) caused a regression in the enclosed test case. The previous approach of calling `Scope#lookup(companionName)` was replaced by a lookup of the scope entry of the original name followed by a narrower search lookup for the companion name, to ensure that it was a true companion, and not just a same-named module from defined at a different nested scope. However, module class symbols are not themselves entered into scopes, so the first part of the new scheme fails. We need to add a special case modules here. I've chosen to just call `.sourceModule` on module classes. For module classes in the current run (all term owned symbols will fall into this category), this amounts to using the value of the field `ModuleClassSymbol#module`.
* Merge pull request #5550 from retronym/ticket/3772Lukas Rytz2016-12-121-0/+21
|\ | | | | SI-3772 Fix detection of term-owned companions
| * Refactor companion lookup methods after code reviewJason Zaugg2016-11-291-1/+1
| |
| * SI-3772 Fix detection of term-owned companionsJason Zaugg2016-11-291-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Companion detection consults the scopes of enclosing Contexts during typechecking to avoid the cycles that would ensue if we had to look at into the info of enclosing class symbols. For example, this used to typecheck: object CC { val outer = 42 } if ("".isEmpty) { case class CC(c: Int) CC.outer } This logic was not suitably hardened to find companions in exactly the same nesting level. After fixing this problem, a similar problem in `Namer::inCurrentScope` could be solved to be more selective about synthesizing a companion object. In particular, if a manually defined companion trails after the case class, don't create an addiotional synthetic comanpanion object.
* | SI-9945 Don't warn imports in java unitsSom Snytt2016-11-161-1/+1
|/ | | | Scaladoc was prone to warning about java imports.
* Javadoc: java static name resolutionAdriaan Moors2016-08-131-1/+10
| | | | [Jakob Odersky <jodersky@gmail.com>: remove obsolete comments and fix tests]
* Add since arg to deprecationWarning and use itSimon Ochsenreither2016-05-291-2/+2
|
* Refactor flag juggling. Review feedback from Jason.Adriaan Moors2016-03-261-0/+2
| | | | Sometimes booleans and a little duplication go a long way.
* Treat `Function` literals uniformly, expecting SAM or FunctionN.Adriaan Moors2016-03-261-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | They both compile to INDY/MetaLambdaFactory, except when they occur in a constructor call. (TODO: can we lift the ctor arg expression to a method and avoid statically synthesizing anonymous subclass altogether?) Typers: - no longer synthesize SAMs -- *adapt* a Function literal to the expected (SAM/FunctionN) type - Deal with polymorphic/existential sams (relevant tests: pos/t8310, pos/t5099.scala, pos/t4869.scala) We know where to find the result type, as all Function nodes have a FunctionN-shaped type during erasure. (Including function literals targeting a SAM type -- the sam type is tracked as the *expected* type.) Lift restriction on sam types being class types. It's enough that they dealias to one, like regular instance creation expressions. Contexts: - No longer need encl method hack for return in sam. Erasure: - erasure preserves SAM type for function nodes - Normalize sam to erased function type during erasure, otherwise we may box the function body from `$anonfun(args)` to `{$anonfun(args); ()}` because the expected type for the body is now `Object`, and thus `Unit` does not conform. Delambdafy: - must set static flag before calling createBoxingBridgeMethod - Refactored `createBoxingBridgeMethod` to wrap my head around boxing, reworked it to generalize from FunctionN's boxing needs to arbitrary LMF targets. Other refactorings: ThisReferringMethodsTraverser, TreeGen.
* Refactor typedFunction, rework synthesizeSAMFunction for sammyAdriaan Moors2016-03-261-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `typedFunction` uniformly recognizes Single Abstract Method types and built-in `FunctionN` types, type checking literals regardless of expected type. `adapt` synthesizes an anonymous subclass of the SAM type, if needed to meet the expected (non-`FunctionN`) type. (Later, we may want to carry `Function` AST nodes with SAM types through the whole pipeline until the back-end, and treat them uniformly with built-in function types there too, emitting the corresponding `invokedynamic` & `LambdaMetaFactory` bytecode. Would be faster to avoid synthesizing all this code during type checking...) Refactor `typedFunction` for performance and clarity to avoid non-local returns. A nice perk is that the error message for missing argument types now indicates with `<error>` where they are missing (see updated check file). Allow pattern matching function literals when SAM type is expected (SI-8429). Support `return` in function body of SAM target type, by making the synthetic `sam$body` method transparent to the `enclMethod` chain, so that the `return` is interpreted in its original context. A cleaner approach to inferring unknown type params of the SAM method. Now that `synthesizeSAMFunction` operates on typed `Function` nodes, we can take the types of the parameters and the body and compare them against the function type that corresponds to the SAM method's signature. Since we are reusing the typed body, we do need to change owners for the symbols, and substitute the new method argument symbols for the function's vparam syms. Impl Notes: - The shift from typing as a regular Function for SAM types was triggered by limitation of the old approach, which deferred type checking the body until it was in the synthetic SAM type subclass, which would break if the expression was subsequently retypechecked for implicit search. Other problems related to SAM expansion in ctor args also are dodged now. - Using `<:<`, not `=:=`, in comparing `pt`, as `=:=` causes `NoInstance` exceptions when `WildcardType`s are encountered. - Can't use method type subtyping: method arguments are in invariant pos. - Can't use STATIC yet, results in illegal bytecode. It would be a better encoding, since the function body should not see members of SAM class. - This is all battle tested by running `synthesizeSAMFunction` on all `Function` nodes while bootstrapping, including those where a regular function type is expected. The only thing that didn't work was regarding Function0 and the CBN transform, which breaks outer path creation in lambdalift.
* Merge pull request #5047 from kmizu/resolve-several-warningsAdriaan Moors2016-03-221-1/+1
|\ | | | | Resolve several deprecation warnings
| * * Replace isPackage with hasPackageFlagKota Mizushima2016-03-171-1/+1
| |
* | New trait encoding: use default methods, jettison impl classesJason Zaugg2016-03-181-1/+0
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Until now, concrete methods in traits were encoded with "trait implementation classes". - Such a trait would compile to two class files - the trait interface, a Java interface, and - the implementation class, containing "trait implementation methods" - trait implementation methods are static methods has an explicit self parameter. - some methods don't require addition of an interface method, such as private methods. Calls to these directly call the implementation method - classes that mixin a trait install "trait forwarders", which implement the abstract method in the interface by forwarding to the trait implementation method. The new encoding: - no longer emits trait implementation classes or trait implementation methods. - instead, concrete methods are simply retained in the interface, as JVM 8 default interface methods (the JVM spec changes in [JSR-335](http://download.oracle.com/otndocs/jcp/lambda-0_9_3-fr-eval-spec/index.html) pave the way) - use `invokespecial` to call private or particular super implementations of a method (rather `invokestatic`) - in cases when we `invokespecial` to a method in an indirect ancestor, we add that ancestor redundantly as a direct parent. We are investigating alternatives approaches here. - we still emit trait fowrarders, although we are [investigating](https://github.com/scala/scala-dev/issues/98) ways to only do this when the JVM would be unable to resolve the correct method using its rules for default method resolution. Here's an example: ``` trait T { println("T") def m1 = m2 private def m2 = "m2" } trait U extends T { println("T") override def m1 = super[T].m1 } class C extends U { println("C") def test = m1 } ``` The old and new encodings are displayed and diffed here: https://gist.github.com/retronym/f174d23f859f0e053580 Some notes in the implementation: - No need to filter members from class decls at all in AddInterfaces (although we do have to trigger side effecting info transformers) - We can now emit an EnclosingMethod attribute for classes nested in private trait methods - Created a factory method for an AST shape that is used in a number of places to symbolically bind to a particular super method without needed to specify the qualifier of the `Super` tree (which is too limiting, as it only allows you to refer to direct parents.) - I also found a similar tree shape created in Delambdafy, that is better expressed with an existing tree creation factory method, mkSuperInit.
* Merge commit 'bb3ded3' into merge-2.11-to-2.12-oct-5Lukas Rytz2015-10-051-1/+6
|\
| * Improve implicits wildcard imports in the IDEJason Zaugg2015-09-301-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In 451cab967a, I changed handling of selection of members from package objects so as to correctly use `somePackage.package.type` as the prefix, rather than `somePackage`. This fixed generic substitution for members inherited from superclasses of the package object. However, this has subtly changed the scope from which we collect implicits given a wildcard import. It seems that the IDE gets into a situation after a scaladoc lookup, which temporarily typechecks the sources of a package object of a third party library, in which the members of package object differ from the members of the enclosing package. The upshot of this was spurious type errors due to implicit search discarding an candidate implicit whose symbol is not matched by typechecking an identifier with the symbol's name at the implicit usage site (this is how we discard shadowed implicits.) I'd like to ge to the bottom of this, but in the meantime, I've found that we can fix the regression by looking up the implicit member symbols in the package, even while correctly using the package object as the prefix.
* | Merge commit 'a170c99' into 2.12.xLukas Rytz2015-09-221-8/+12
|\|
| * Try harder to avoid reporting unpositioned errorsJason Zaugg2015-09-021-8/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rather than issuing an error at NoPosition, which usually means an unpositioned tree is being typechecked, walk up the context chain for an enclosing positioned tree. I've tested this manually with ensime which was getting an unpositioned warning as a result of a unpositioned trees created by a macro in scalatest. ``` % ../scala-positioned-error/build/quick/bin/scalac @args.txt /Users/jason/code/ensime-server/core/src/it/scala/org/ensime/core/RichPresentationCompilerSpec.scala:216: warning: implicit numeric widening ) { (p, cc) => ^ ```
* | SI-9479 Fix regression w. inherited overloads in package objectJason Zaugg2015-09-191-3/+5
| | | | | | | | | | | | | | | | | | | | One shouldn't base any decisions of the owner of an overloaded symbol. Instead, the owner of each of the alternatives should be considered. This gotcha is super easy to forget, as I did with my change to simplify the way we detect whether we need to add the `.package` prefix to a tree.
* | Merge remote-tracking branch 'origin/2.11.x' into ↵Jason Zaugg2015-07-231-3/+3
|\| | | | | | | merge/2.11.x-to-2.12.x-20152307
| * Fix 6 typos (w-z)Janek Bogucki2015-07-171-3/+3
| |
* | Merge pull request #4616 from som-snytt/issue/9383Seth Tisue2015-07-201-24/+29
|\ \ | | | | | | SI-9383 Improved unused import warning
| * | SI-9383 Name the function for implicit importingSom Snytt2015-07-161-6/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Per review, adds a function that clarifies the purpose of the code path that collects imported implicits, namely, to examine qualifying imported implicits and then collect them. In the context of doing something with the import (besides importing), it's clear why we don't want to record that we used the import, that is, because we might be doing something other than using. That's clear, right?
| * | SI-9383 Improved unused import warningSom Snytt2015-07-081-19/+19
| | | | | | | | | | | | | | | | | | | | | 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 23 typos (m-o)Janek Bogucki2015-06-281-1/+1
| |
* | SI-9326 Binding to existentials can discard the prefixJason Zaugg2015-05-251-6/+8
| | | | | | | | | | | | | | | | Refines the previous commit by changing `Context#lookup` to consider existential quantifiers, in the same manner as type parameters, as exempt from consideration of the lookup prefix. Furthermore, this logic is shared with `isInPackageObject`.
* | SI-9326 Fix regression with existentials in parent typesJason Zaugg2015-05-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The typechecker rewrites `p.foo` to `p.<package>.foo` if `foo` must come from a package object. This logic was overhauled in 51745c06f3, but this caused a regression. I reverted to the predecessor of that commit to see how things worked before. The lookup of the name `X` bound to the existential quantifier, but incorrectly included the prefix `test.type` in the result of the lookup. However, the subsequent call to `isInPackageObject` (from `makeAccessible`) returned false, so we didn't try to rewrite `X` to `test.<package>.X`. This commit makes a minimal fix that makes `isInPackageObject` return false for existentials.
* | Merge remote-tracking branch 'origin/2.11.x' into ↵Jason Zaugg2015-05-011-4/+4
|\| | | | | | | merge/2.11.x-to-2.12.x-20150501
| * Fix many typosMichał Pociecha2015-04-211-4/+4
| | | | | | | | | | This commit corrects many typos found in scaladocs and comments. There's also fixed the name of a private method in ICodeCheckers.
* | SI-9074 Fix generic substitution with package objects, overloadingJason Zaugg2015-03-241-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Takes a leaf out of dotty's book [1] and makes `asSeenFrom` transparently change the prefix from the package class to the package object when needed. This fixes generic subsitution during overload resolution, as reported in SI-9074. This subsumes the former fix for SI-6225, which is removed here. [1] https://github.com/lampepfl/dotty/pull/282
* | Merge remote-tracking branch 'origin/2.11.x' into ↵Jason Zaugg2015-01-291-5/+5
|\| | | | | | | | | | | | | | | | | 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-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | 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 '7ba38a0' into merge/2.11.x-to-2.12.x-20150129Jason Zaugg2015-01-291-4/+7
|\| | | | | | | | | | | | | | | Conflicts: build.number src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala src/library/scala/collection/Iterator.scala versions.properties
| * Merge pull request #4169 from retronym/ticket/9008Adriaan Moors2014-12-051-1/+2
| |\ | | | | | | SI-9008 Fix regression with higher kinded existentials
| | * SI-9008 Fix regression with higher kinded existentialsJason Zaugg2014-12-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow a naked type constructor in an existential type if we are directly within a type application. Recently, 84d4671 changed nested context creation to avoid passing down the `TypeConstructorAllowed`, which led to missing kind errors in code like `type T[({type M = List})#M]`. However, when typechecking `T forSome { quantifiers }`, we create a nested context to represent the nested scope introduced for the quantifiers. But we need to propagate the `TypeConstructorAllowed` bit to the nested context to allow for higher kinded existentials. The enclosed tests show: - pos/t9008 well kinded application of an hk existential - neg/t9008 hk existential forbidden outside of type application - neg/t9008b kind error reported for hk existential Regressed in 84d4671.
| * | SI-8995: Fix broken link in error messageDenton Cockburn2014-11-301-1/+1
| |/ | | | | | | | | Change broken link to scala-xml documentation by pointing instead to scala-xml project.
| * SI-5639 Predicate bug fix on -Xsource:2.12Jason Zaugg2014-11-181-1/+1
| | | | | | | | | | | | To be conservative, I've predicated this fix in `-Xsource:2.12`. This is done in separate commit to show that the previous fix passes the test suite, rather than just tests with `-Xsource:2.12`.
| * SI-5639 Fix spurious discarding of implicit importJason Zaugg2014-11-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Scala fa0cdc7b (just before 2.9.0), a regression in implicit search, SI-2866, was discovered by Lift and fixed. The nature of the regression was that an in-scope, non-implicit symbol failed to shadow an eponymous implicit import. The fix for this introduced `isQualifyingImplicit` which discards in-scope implicits when the current `Context`'s scope contains a name-clashing entry. Incidentally, this proved to be a shallow solution, and we later improved shadowing detection in SI-4270 / 9129cfe9. That picked up cases where a locally defined symbol in an intervening scope shadowed an implicit. This commit includes the test case from the comments of SI-2866. Part of it is tested as a neg test (to test reporting of ambiguities), and the rest is tested in a run test (to test which implicits are picked.) However, in the test case of SI-5639, we see that the scope lookup performend by `isQualifyingImplicit` is fooled by a "ghost" module symbol. The apparition I'm referring to is entered when `initializeFromClassPath` / `enterClassAndModule` encounters a class file named 'Baz.class', and speculatively enters _both_ a class and module symbol. AFAIK, this is done to defer parsing the class file to determine what inside. If it happens to be a Java compiled class, the module symbol is needed to house the static members. This commit adds a condition that `Symbol#exists` which shines a torch (forces the info) in the direction of the ghost module symbol. In our test, this causes it to vanish, as we only need a class symbol for the Scala defined `class Baz`. The existing `pos` test for this actually did not exercise the bug, separate compilation is required. It was originally checked in to `pending` with this error, and then later moved to `pos` when someone noticed it was not failing.
| * SI-8962 Fix regression with skolems in pattern translationJason Zaugg2014-11-061-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During the refactoring of error reporting in 258d95c7b15, the result of `Context#reportError` was changed once we had switched to using a `ThrowingReporter`, which is still the case in post typer phase typechecking This was enough to provoke a type error in the enclosed test. Here's a diff of the typer log: % scalac-hash 258d95~1 -Ytyper-debug sandbox/test.scala 2>&1 | tee sandbox/good.log % scalac-hash 258d95 -Ytyper-debug sandbox/test.scala 2>&1 | tee sandbox/bad.log % diff -U100 sandbox/{good,bad}.log | gist --filename=SI-8962-typer-log.diff https://gist.github.com/retronym/3ccbe7e0791447d272a6 The test `Context#reportError` happens to be used when deciding whether the type checker should be lenient when it hits a type error. In lenient mode (see `adaptMismatchedSkolems`), it `adapt` retries with after slackening the expected type by replacing GADT and existential skolems with wildcard types. This is to accomodate known type-incorrect trees generated by the pattern matcher. This commit restores the old semantics of `reportError`, which means it is `false` when a `ThrowingReporter` is being used. For those still reading, here's some more details. The trees of the `run2` example from the enclosed test. Notice that after typechecking, `expr` has a type containing GADT skolems. The pattern matcher assumes that calling the case field accessor `expr` on the temporary val `x2 : Let[A with A]` containing the scrutinee will result in a compatible expression, however this it does not. Perhaps the pattern matcher should generate casts, rather than relying on the typer to turn a blind eye. ``` [[syntax trees at end of typer]] // t8962b.scala ... def run2[A](nc: Outer2[A,A]): Outer2[Inner2[A],A] = nc match { case (expr: Outer2[Inner2[?A2 with ?A1],?A2 with ?A1])Let2[A with A]((expr @ _{Outer2[Inner2[?A2 with ?A1],?A2 with ?A1]}){Outer2[Inner2[?A2 with ?A1],?A2 with ?A1]}){Let2[A with A]} => (expr{Outer2[Inner2[?A2 with ?A1],?A2 with ?A1]}: Outer2[Inner2[A],A]){Outer2[Inner2[A],A]} }{Outer2[Inner2[A],A]} [[syntax trees at end of patmat]] // t8962b.scala def run2[A](nc: Outer2[A,A]): Outer2[Inner2[A],A] = { case <synthetic> val x1: Outer2[A,A] = nc{Outer2[A,A]}; case5(){ if (x1.isInstanceOf[Let2[A with A]]) { <synthetic> val x2: Let2[A with A] = (x1.asInstanceOf[Let2[A with A]]: Let2[A with A]){Let2[A with A]}; { val expr: Outer2[Inner2[?A2 with ?A1],?A2 with ?A1] = x2.expr{<null>}; matchEnd4{<null>}((expr{Outer2[Inner2[?A2 with ?A1],?A2 with ?A1]}: Outer2[Inner2[A],A]){Outer2[Inner2[A],A]}){<null>} ... ```
* | Merge commit 'eb15950' into merge/2.11.x-to-2.12.x-20150129Jason Zaugg2015-01-291-0/+2
|\|
| * SI-8869 Prevent ill-kindedness in type lambdasJason Zaugg2014-10-011-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When type checking an type application, the arguments are allowed to be of kinds other than *. This leniency is controlled by the `ContextMode` bit `TypeConstructorAllowed`. (More fine grained checking of matching arity a bounds of type constructors is deferred until the refchecks phase to avoid cycles during typechecking.) However, this bit is propagated to child contexts, which means that we fail to report this error in the lexical context marked here: T[({type x = Option}#x)] `-------------' This commit resets this bit to false in any child context relates to a different tree from its parent.
* | More uniform treatment of package objectsJason Zaugg2014-11-071-54/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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-1/+7
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.