aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Implicits.scala
Commit message (Collapse)AuthorAgeFilesLines
* Clean up config.Printers importsOlivier Blanvillain2016-09-231-1/+1
| | | | And remove the not used Printer#echo
* Partially fix #1500: Implicit search breaks at a certain depthOlivier Blanvillain2016-09-131-4/+5
| | | | | | The issue fixed here was introduced by 71027f15. The added `csyms.isEmpty` condition on `case nil =>` is always true, which is clearely a bug. t1500c still fails with covariant (or contravariant) type parameters on `::`, but this seams to be a more complicated issue involving the typer.
* New string infterpolatorsMartin Odersky2016-08-161-9/+11
| | | | | | Roll `sm` and `i` into one interpolator (also called `i`) Evolve `d` to `em` interpolator (for error messages) New interpolator `ex` with more explanations, replaces disambiguation.
* Fix #1284: Make classTag depend directly on erasureMartin Odersky2016-07-251-9/+7
| | | | | | In the end, a classTag reflects the erased version of a type. The only condition for its generation should be that the erasure is stable under possible instantiations.
* Drop Config.checkKindsMartin Odersky2016-07-111-1/+1
| | | | | Allows us to drop also the involved knownHK method. Lots of other cleanups.
* Handle WildcardType in liftToClassesMartin Odersky2016-07-111-0/+1
|
* When comparing types revert eta-expansion as neededMartin Odersky2016-07-111-0/+8
| | | | | | | | | | | | | The problem is that some existential types read from Java (and Scala as well? not sure) appear as naked typerefs. They consequently get expanded via eta expansion to type lambdas. This commit compensates for this by collapsing an eta expansion if this can make a subtype tests succeed or a union or intersection be legal. Also, take hk types into account for liftToClasses Needs to special-treat TypeLambda and HKApply since otherwise we risk creating malformed And-types.
* Remove old hk schemeMartin Odersky2016-07-111-4/+1
| | | | | | | | | | | | - Simplify RefinedType - Drop recursive definition of RefinedThis - this is now taken over by RecType. - Drop RefinedThis. - Simplify typeParams The logic avoiding forcing is no longer needed. - Remove unused code and out of date comments.
* Change testsMartin Odersky2016-07-111-2/+2
| | | | | | | | | | | | | | | | - compileMixed failed because there was a cycle between immutable.Seq (compiled) and parallel.ParSeq (loaded from classfile). Inspection of the completion log (turn completions Printer on) and the stack trace showed that there's nothing we can do here. The old hk scheme did not go into the cycle because it did not force an unrelated type. I believe with enough tweaking we would also hva egotten a cycle in the old hk scheme. The test is "fixed" by adding parallel.ParSeq to the files to compile. - Disable named parameter tests Those tests do not work yet with the revised hk scheme. Before trying to fix this, we should first decide what parts of named parameters should be kept.
* Abstract type parameters out from type symbolsMartin Odersky2016-07-111-1/+1
| | | | | | | | In the new hk scheme, a type parameter can be represented by a refinement without a corresponding symbol. Therefore, we need to disentangle the info inherent in a type parameter from the contents of a type symbol. We achieve this by creating a common super trait "MemerInfo" of Symbol and RefinedType.
* Don't compute implicit scopes for synthetic Lambda traitsGuillaume Martres2016-05-311-1/+4
|
* Avoid creating AndTypes with AnyGuillaume Martres2016-05-311-1/+1
| | | | This reduces the number of implicit scopes we cache.
* OfTypeImplicits: compute refs lazilyGuillaume Martres2016-05-311-1/+1
| | | | | | Many intermediate `OfTypeImplicits` are created during a call to `implicitScope`, but they won't all be used so there is no need to compute `OfTypeImplicits#refs` unless it's actually used.
* Do not miss implicits in type parameters of parentsGuillaume Martres2016-05-311-1/+1
| | | | | This did not work before because we incorrectly looked for their value in the prefix of the type instead of the type itself.
* Fix implicit scope caching bugGuillaume Martres2016-05-311-5/+6
| | | | | | | | | | | | | | The issue is subtle: the `tp` in scope in `def ofTypeImplicits` is the `tp` passed to the top-level `implicitScope` method, not the `tp` passed to the recursively called `iscope`, this means that before this commit, all intermediate `OfTypeImplicit` scopes cached while computing an implicit scope had their `tp` field incorrectly set, which means that we could miss implicits in later implicit searches. Note that the `implicit_cache.scala` test worked before this commit because of the restrictions on caching that exist since b8b0f381ef2cbcb7bad66fd3e7a9ae929baa45f6, it is included anyway because our caching strategy might change in the future.
* Document why we cannot cache all implicit scopesGuillaume Martres2016-05-311-1/+12
|
* Move eqAny to PredefMartin Odersky2016-05-231-2/+2
|
* Add Eq instances of standard types to PredefMartin Odersky2016-05-231-2/+14
| | | | | | | | | To make tests pass, this required a looser specification of `assumedCanEquals`, so that an abstract type T can be compared to arbitrary values, as long as its upper bound can be compared. E.g. T == null T == "abc"
* Tweak of valid eqAny conditionMartin Odersky2016-05-231-39/+30
|
* Make use of implicitNotFound for eqaulity errorsMartin Odersky2016-05-231-3/+1
| | | | | Needed a fix in string interpolation for suriviving inserted types that contain `$` characters.
* Print diagnostics to implicits printerMartin Odersky2016-05-231-2/+2
|
* Check equality that with == and != makes senseMartin Odersky2016-05-231-11/+43
| | | | | | This is done by checking each instance of an eqAny implicit so that it does not contain non-bottom instances of equality types as instances.
* Hooks to check that comparisons with == / != make senseMartin Odersky2016-05-231-0/+64
| | | | | | | | | | Also, check that pattern matching against idents/selects/literals makes sense. The hooks perform an implicit search for an instance of `Eq[L, R]`, where `L`, `R` are the argument types. So far this always succeeeds because Eq.eqAny matches all such types. A separate commit will check the returned search term for validity.
* Downwards comparisons for implicit search and overloading resolutionMartin Odersky2016-05-231-1/+13
| | | | | | | | | Compare selected contravariant arguments as if they were covariant. Which ones is explained in the doc comment for method `isAsSpecificValueType` in Applications.scala. This has the same motivation than what @paulp proposed around 2012. The solution is a bit different from the one proposed then because it only affects top-level parameters.
* Fix caching problem when computing implicit scopesMartin Odersky2016-05-231-1/+1
| | | | | | Caches were set when information was not complete yet. Problem was exhibited by missing some `eqName` implicits when adding safe equality for Name.
* Do the implicit search shadowing check in the correct contextGuillaume Martres2016-03-031-2/+2
| | | | | | | | | | | | | | | | | This commit fixes a very sneaky bug, the following code: ``` lazy val shadowing = typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto) (nestedContext.addMode(Mode.ImplicitShadowing).setExploreTyperState) ``` is parsed by scalac as: ``` lazy val shadowing = typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto); (nestedContext.addMode(Mode.ImplicitShadowing).setExploreTyperState); ``` So we don't actually use the nested context in `typed`, instead we end up implicitly using `ctx`!
* Survive class of errors in implicit searchMartin Odersky2016-02-121-1/+2
| | | | | | | | An `C.this` term with erroneous class `C` will get a `NoPrefix` type. A subsequent implicit search on this crashed. This is fixed now. Fixes #324.
* Fix #1044: handle TypevarsMissContext mode in wildApproxGuillaume Martres2016-02-061-0/+2
| | | | | | | | | | | | | | When `wildApprox` encounters a PolyParam it approximates it by its bounds in the current constraint set, but this is incorrect if `TypevarsMissContext` is set, we might get the bounds of another use of this `PolyType`. This is exactly what happened in i1044.scala where the implicit view `refArrayOps` needs to be used twice with two different type parameters. The fix is to approximate a PolyParam by its original bounds in its PolyType if `TypevarsMissContext` is set. This fix was inspired by the approach of #1054.
* Merge pull request #902 from dotty-staging/fix-numeric-implicit-argsodersky2015-11-091-4/+26
|\ | | | | Fix numeric implicit args
| * Disable failing testMartin Odersky2015-11-011-5/+5
| | | | | | | | | | Dotty delivers an ambiguity error. The comment in the test argues why this is OK.
| * Better handling of implicits over numeric types.Martin Odersky2015-11-011-4/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Compiling scala.math.BigDecimal and scala.math.BigInteger shows a problem. The conversion `int2bigInt` is not applicable to a Byte because `Byte -> Int` requires another implicit conversion. We fix that by using a new method relaxed_<:< for implicit compatibility checks, which always admits numeric widenings. This leads to another problem. Now the conversions implicit def byteToInt(x: Byte): Int implicit def byteToShort(x: Byte): Short are ambiguous when we try to convert from Byte to Int. We fix that by adding a "tie-break" to implicit search where if several methods match a numeric value result type and all have numeric value types as result types, we pick the numerically largest type that matches.
* | Enable <:< implicits as conversions.Martin Odersky2015-11-031-1/+3
|/ | | | | | | | These were disabled before, which means that having evidence of S <:< T did not introduce a usable implicit conversion from S to T. We do do it like scalac: just disable Predef.$conforms. This makes TraversableOnce compile. Fixes #914.
* Shorten ctx.typerState.reporter to ctx.reporterMartin Odersky2015-10-261-1/+1
| | | | ... making use of method in `ctx`.
* Add @sharable annotationMartin Odersky2015-07-061-1/+1
| | | | | | | Add @sharable annotation for classes and vals that are presumed to be safely sharable between threads. Also: Document CtxLazy.
* setNewTyperState -> setExploreTyperState when computing shadoing implicitsMartin Odersky2015-06-241-1/+5
| | | | Nothing will be committed here, so setExplore... is the right method to pick.
* Avoid follow-on errors after implicit argument errors.Martin Odersky2015-06-231-1/+1
| | | | Previously, we could die with a <notype> when an implicit argument was not found.
* Do not check for ambiguous implicits in viewExistsMartin Odersky2015-06-221-3/+8
| | | | | | | | | | | | | | | | | | | | | Previously `viewExists(X, Y)` failed if there were ambiguous implicit conversions from X to Y. This is too fragile, as demonstrated by test case run/array-addition.scala. Here, the `genericArrayOps` implicit was not inserted because its result type `Array[?T]` was deemed to be incompatible with `? { +: : ? }`. It was incompatible because there were multiple implicits that added :+ to arrays of various element types. But once `genericArrayOps` gets applied, the type parameter `?T` of the array result is fixed, and the ambuity goes away. The scenario shows that we should not test for ambiguous implicits in viewExists. Such a test is fragile because it depends on the progress of type inference when the test is made. It's preferable to just test for any implicit conversion to exist and to check for ambiguities later, when the implicit conversion is actually applied. This has also the potential of speeding up implicit search in situations where `viewExists` is called often (e.g. when coupled with overloading resolution).
* Avoid double context creation when modes change on a fresh context.Martin Odersky2015-06-221-2/+3
| | | | | | | | | | | | | | | | | | | | Move addMode and friends to two decorators, one for Context, the other for FreshContext. Implement behavior accordingly. This avoids creating two contexts in situations like: c.fresh.setxploreTyperState.addMode(...) Mow we can write c.fresh.addMode(...).setExploreTyperState Because addMode returns a fresh context when applied to a fresh context. Note that we specifically do not want virtual dispatch of addMode, that's why it was moved to a decorator. Also: removed mention of ".fresh: when just forllowed by an addMode, because that one is redundant.
* Refactor viewExistsMartin Odersky2015-06-191-15/+4
| | | | | Factor out isValueSubClass into separate method. Will probably come in handly elsewhere, and makes the code easier to understand.
* Fix stack overflow when testing for shadowingMartin Odersky2015-06-191-2/+3
| | | | | | | | | Shadowing tests could go into an infinite recursion when the found sahdwoing member itself needs an implicit that is resolved and then shadowed again by the same member. A test case is neg/arrayclone-new.scala. This caused a SO before, now gives two errors.
* Correct a large number of typos.Jason Zaugg2015-05-141-2/+2
| | | | | I scanned the main sources with IntellIJ's spell checker and corrected what showed up.
* Ensure spaces after `if` in Dotty source.Dmitry Petrashko2015-04-091-1/+1
|
* Remove trailing spaces in Dotty source.Dmitry Petrashko2015-04-091-1/+1
|
* Implicits#viewExists: return false after typer instead of AssertionErrorGuillaume Martres2015-03-271-0/+1
| | | | | | | | This way, tpd#applyOverloaded can safely be used after typer. This issue was encoutered while working on value classes, step 3 of SIP-15 contains the following peephole optimization: new C(e) == new C(f) => e == f Which requires us to do overloading resolution.
* Fix implicit problem in RefinedPrinter.Martin Odersky2015-03-181-1/+1
| | | | | | | The implicit def was shadowed by a following import. Scalac did not detect the problem probably because the import and the def were in the same scope. But selecting the member explicitly would have caused an error because the import came after the definition. So arguably this was in error, but scalac did not detect it correctly.
* Fix implicitScope for the case when implicit scopes cannot be cachedOndrej Lhotak2015-02-051-16/+20
| | | | | | | | | This fixes #347. When Config.cacheImplicitScopes == false or an implicit scope is requested for a type for which it cannot be cached, this change causes the same computation to be applied as if the scope were looked up in the implicit scope cache and not found.
* Fixups taking into account reviewer's comments.Martin Odersky2015-01-271-4/+2
|
* Some small polishings in TypeComparerMartin Odersky2015-01-241-1/+1
|
* New scheme for subtyping refined types.Martin Odersky2015-01-081-1/+4
| | | | | | | | | | | | | | | | - Instead of rebasing, use the DeBrujn level of a RefiendThis. - Make sure lower type is a singleton by skolemizing it if necessary. - Do the correct rebinding of the upper type's RefinedThis. Remarks: - The new scheme discovered quite a lot of errors which are mostly fixded in other commits of this branch. i0268 (GADT matching) still does not work, moved to pending. - Some optimizations are currently missing: (1) fast path refined subtyping (2) faster operations for substituting refined thistypes which explot the fact that RefinedThis is relatively rare.
* Disable implicit conversions between from `Null` and `Nothing`.Martin Odersky2014-12-131-1/+3
| | | | | | | | | | | | This is necessary to reject code like val x: Boolean = null Without the restriction, this code would typecheck and expand to val x: Boolean = Predef.Boolean2boolean(null) since `null` counts as a value of type `java.kang.Boolean`.