summaryrefslogtreecommitdiff
path: root/src/compiler
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #3037 from gkossakowski/fix-merge-3018v2.11.0-M6Grzegorz Kossakowski2013-10-142-17/+199
|\ | | | | [resubmit] Experimental Single Abstract Method support (sammy meets world)
| * Merge remote-tracking branch 'scala/master' into fix-merge-3018Grzegorz Kossakowski2013-10-147-379/+206
| |\ | | | | | | | | | | | | Conflicts: src/compiler/scala/tools/nsc/typechecker/Typers.scala
| * | Remove stray debug commentAdriaan Moors2013-10-081-2/+0
| | |
| * | Extract SerialVersionUIDAnnotation. Make SAM body synthetic.Adriaan Moors2013-10-082-11/+6
| | | | | | | | | | | | Addressing review feedback.
| * | Don't pursue SAM translation after an arity mismatch.Jason Zaugg2013-10-081-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change: scala> trait T { def apply(a: Int): Int } defined trait T scala> ((x: Int, y: Int) => 0): T <console>:9: error: object creation impossible, since method apply in trait T of type (a: Int)Int is not defined ((x: Int, y: Int) => 0): T ^ After the change, these cases report the same errors as they do *without* -Xexperimental.
| * | Single Abstract Method support: synthesize SAMsAdriaan Moors2013-10-041-10/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Under `-Xexperimental`, `typedFunction` invokes `synthesizeSAMFunction` when the expected type for the function literal (`pt`) is not the built-in `FunctionN` type of the expected arity, but `pt` does have a SAM with the expected number of arguments. PS: We'll require `import language.sam` instead of `-Xexperimental`, as soon as the SIP is ready and there are more tests.
| * | Single Abstract Method support: synthesis helpersAdriaan Moors2013-10-041-0/+154
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `synthesizeSAMFunction` will be used to expand the following tree: ``` { (p1: T1, ..., pN: TN) => body } : S ``` to: ``` { def apply$body(p1: T1, ..., pN: TN): T = body new S { def apply(p1: T1, ..., pN: TN): T = apply$body(p1,..., pN) } } ``` The expansion assumes `S` (the expected type) defines a single abstract method (let's call that method `apply` for simplicity). 1. If 'T' is not fully defined, it is inferred by type checking `def apply$body` without a result type before type checking the block. The method's inferred result type is used instead of T`. [See test/files/pos/sammy_poly.scala] 2. To more easily enforce S's members are not in scope in `body`, that tree goes to the `apply$body` method that's outside the anonymous subclass of S. (The separate `apply$body` method simplifies the implementation of 1&2.) 3. The following restrictions apply to S: 1. Its primary constructor (if any) must be public, no-args, not overloaded. 2. S must have exactly one abstract member, its SAM 3. SAM must take exactly one argument list 4. SAM must be monomorphic We may later relax these requirements to allow an implicit argument list, both on the constructor and the SAM. Could also let the SAM be polymorphic.
| * | Simplify partest.task target, fix typo in comment.Adriaan Moors2013-10-041-1/+1
| | |
* | | Merge pull request #3038 from retronym/topic/by-name-revertGrzegorz Kossakowski2013-10-142-3/+9
|\ \ \ | | | | | | | | SI-7899 Allow by-name inference under -Yinfer-by-name
| * | | SI-7899 Allow by-name inference under -Yinfer-by-nameJason Zaugg2013-10-142-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As usual, the hole has been exploited in the wild. While you can't abstract over by-name-ness without running into the ClassCastException or an un-applied Function0, there are cases like the enclosed test where you can tiptoe around those cases. I've proposed a small change to Scalaz to avoid tripping over this problem: https://github.com/scalaz/scalaz/pull/562/files But this commit I've also added a transitional flag, -Yinfer-by-name, that they could use to back-publish older versions without code changes. It is also an insurance policy for other projects that might be exploiting the same hole.
* | | | Aesthetics in GenTrees.Paul Phillips2013-10-131-24/+13
| |_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A nominee for "worst textual shape" might be \\\\\ ///// \\\\\ ///// \\\\\ ///// where the zigzagging wall of text is confined to the first forty columns. In this commit we halve the vertical space usage and double the readability.
* | | Merge pull request #3024 from retronym/ticket/7895Paul Phillips2013-10-122-25/+49
|\ \ \ | |/ / |/| | SI-7895 Error reporting: avoid cascading, truncation
| * | SI-7985 Typecheck args after failure to typecheck functionJason Zaugg2013-10-091-6/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `missing1.foo(missing2)` now reports `missing1` and `missing2` as not found. Previously, only the first was reported. The arguments are typed with an expected type ErrorType. We propagate this through as the inferred type of anonymous function parameters to avoid issuing cascading "missing parameter type" errors in code like: scala> Nil.mapp(x => abracadabra) <console>:8: error: value mapp is not a member of object Nil Nil.mapp(x => abracadabra) ^ <console>:8: error: not found: value abracadabra Nil.mapp(x => abracadabra) ^ This was in response to unwanted changes in the output of existing neg tests; no new test is added. Similarly, we refine the errors in neg/t6436b.scala by to avoid cascaded errors after: type mismatch; found: StringContext, required: ?{def q: ?}
| * | SI-7895 Issue all buffered errors after silent mode.Jason Zaugg2013-10-092-19/+26
| | | | | | | | | | | | | | | | | | | | | Rather than just the first. For example, `foo(wizzle, wuzzle, woggle)` should report all three not-found symbols.
| * | SI-7895 Avoid cascade of "symbol not found" in pattern matchesJason Zaugg2013-10-091-3/+10
| |/ | | | | | | | | | | If we can't type check the `Foo` in `case Foo(a, b) => (a, b)`, we should enter error symbols for `a` and `b` to avoid further errors being reported in the case body.
* | Merge pull request #3020 from paulp/pr/overriding-pairsJason Zaugg2013-10-094-352/+154
|\ \ | | | | | | Generalize OverridingPairs to SymbolPairs.
| * | Generalize OverridingPairs to SymbolPairs.Paul Phillips2013-10-054-352/+154
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Increases your chance of knowing what is going on in OverridingPairs. Introduces some new abstractions which I hope for your own sakes you will put to use in some way: RelativeTo: operations relative to a prefix SymbolPair: two symbols being compared for something, and the enclosing class where the comparison is being performed Fixed a minor bug with access by accident by way of more principled pair analysis. See run/private-override.scala. Upgraded the error message issued on certain conflicts to give the line numbers of both conflicting methods, as opposed to just one and you go hunting.
* / SI-7899 Don't infer by-name types during, e.g. eta-expansionJason Zaugg2013-10-071-2/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Given: def id[A](a: A): A = a def foo(f: (=> Int) => Int) = () foo(id) We eta-expanded `id` and inferred `A` to be `=> Int` to satisfy the expected type set forth by the formal parameter `f`. We really shouldn't go about inferring types that we can't *write*. Our attempt to do so led promptly into a `ClassCastException` in the enclosed test. This commit: - drops by-name-ness during `inferExprInstance` - tests that this results in a type error for the reported bug (neg/t7899) - tests that a method with a by-name parameter can still be eta expanded to match function with a corresponding by-name parameter (run/t7899) - discovers the same latent CCE in pos/t7584 - now that would be a type error - so we compensate by using placeholder functions rather than eta-expansion. - and move that that test to `run` for good measure.
* Merge pull request #3005 from paulp/pr/7886Paul Phillips2013-10-033-21/+26
|\ | | | | SI-7886 unsoundness in pattern matcher.
| * SI-6680 unsoundness in gadt typing.Paul Phillips2013-10-012-20/+24
| | | | | | | | | | | | | | Introduces -Xstrict-inference to deal with the significant gap between soundness and what presently compiles. I'm hopeful that it's TOO strict, because it finds e.g. 75 errors compiling immutable/IntMap.scala, but it might be that bad.
| * SI-7886 unsoundness in pattern matcher.Paul Phillips2013-10-012-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I tracked down what was behind the issue described here: // TODO: fix the illegal type bound in pos/t602 -- type inference // messes up before we get here: /*override def equals(x$1: Any): Boolean = ... // Span[Any] --> Any is not a legal type argument for Span! val o5: Option[com.mosol.sl.Span[Any]] = */ ...which led straight to the unsoundness seen in neg/t7886. It is dangerous to have an expected type of "Any" because the type system will blithely ignore kind errors, since "Any" can absorb anything. The consequence in this instance was that inferring the case constructor for a type like Foo[T <: Bound] if done with expected type Any, this would come up with Foo[Any]. I altered it to use expected type Foo[T], which lets the dummy type parameter survive to carry the bound forward and restores sense to the inference. The before/after output for -Xprint:patmat on pos/t602.scala is: 15c15 < if (x1.isInstanceOf[com.mosol.sl.Span[Any]]) --- > if (x1.isInstanceOf[com.mosol.sl.Span[K]]) 17c17 < <synthetic> val x2: com.mosol.sl.Span[Any] = \ (x1.asInstanceOf[com.mosol.sl.Span[Any]]: com.mosol.sl.Span[Any]); --- > <synthetic> val x2: com.mosol.sl.Span[K] = \ (x1.asInstanceOf[com.mosol.sl.Span[K]]: com.mosol.sl.Span[K]); 19,20c19,20 < val low$0: Option[Any] = x2.low; < val high$0: Option[Any] = x2.high; --- > val low$0: Option[K] = x2.low; > val high$0: Option[K] = x2.high; A file in the library depended (needlessly) on the unsoundness. It was easy to fix but reminds us this may affect existing code.
* | Merge pull request #2965 from retronym/ticket/7859Grzegorz Kossakowski2013-10-032-11/+22
|\ \ | | | | | | SI-7859 Value classes may wrap a non-public member
| * | SI-7859 Value classes may wrap a non-public memberJason Zaugg2013-09-292-11/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We allow value class constructors to be non-public, so to be regular, we should also allow the same for the param accessor. This commit uses the 'makeNotPrivate' machinery to ensure that the backend can generate the requisite unboxing calls. This commit: - refactors the code that enforced the restrictions, improving a few error messages and positions. The remaining restrictions needed some rewording in light of this change. - allows value classes to have non-public, val parameters. private[this] / protected[this] are still disallowed as value classes don't have a concept of `this`, and because trying to accomdate then would complicate the implementation. This means that `class C(x: Int) extends AnyVal` is not allowed, the user still must write `private val x: Int` or `val x: Int`. - Outlaw `class C()()(val x: Int) extends AnyVal` to curtail any bugs that might lurk in such a formulation. The tests: - Show that the privacy is respected in the typer phase, under joint and separate compilation. We don't want a repeat performance of SI-6601. - Show that code that needs compiler-generated unboxes works under both compilation scenarios - Checks that the remaining restrictions are enforced and well communicated.
* | | Merge pull request #2994 from xeno-by/topic/bundlesJason Zaugg2013-10-033-29/+39
|\ \ \ | | | | | | | | assorted fixes for bundles
| * | | gets rid of randomness in virtual filenames for bundlesEugene Burmako2013-10-022-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bundles are emitted in compilation units that wrap virtual source files. Previously we had those virtual files named randomly to ensure freshness, but that led to infinite compilation loops in SBT (see the commit message for more details and a link to a scala-user discussion). Now the names are generated deterministically from full names of bundles, which fixes the problems with SBT.
| * | | clearly establishes what macro bundles areEugene Burmako2013-10-022-19/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously it was enough to just extend scala.reflect.macros.Macro, which created some loopholes, but now scalac enforces that bundles: 1) Are static (not necessarily top-level, but just static) 2) Are traits (objects shouldn't be bundles anyway, and classes bring complications with their ctors which require special treatment in generated classes, so why support them if they don't bring anything new to the table?) 3) Are monomorphic (again, this brings unnecessary complications wrt auxiliary code generation, so I don't see merit in supporting polymorphic bundles, whatever that a polymorphic bundle could mean) 4) Don't provide concrete implementation for Macro.c (if they do then what is the point?)
* | | | Merge pull request #2977 from ↵Jason Zaugg2013-10-033-4/+12
|\ \ \ \ | |/ / / |/| | | | | | | | | | | sjrd/topic/remove-classpath-logic-dependent-on-inline Don't avoid to load trait impl .class without inliner.
| * | | Add -Yno-load-impl-class disabling loading of $class.class files.Sébastien Doeraene2013-09-272-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The parent commit, a3f71badf67bbaac1a4ba16f68211ea6e31aa473, removed some logic preventing $class.class files to be loaded. It did so only when the inliner was off. Should this cause any issue, this option provides a means to restore the old behavior by *never* loading $class.class files. So, using -inline -Yno-load-impl-class will not load $class.class files either (where previously -inline would load them). The two old behaviors being available by *either* using -inline *or* -Yno-load-impl-class (not both).
| * | | Don't avoid to load trait impl .class without inliner.Sébastien Doeraene2013-09-192-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the inliner is on, it is necessary to load class files containing the implementation of traits, i.e., those ending in $class.class. This is needed to be able to inline these methods. However it is useless if the inliner is disabled. The previous logic avoided to put these files on the classpath when the inliner was off. However, this complicates things, and it makes the classpath mechanism dependent on something totally unrelated. On this basis, this commit removes that logic, and instead trait impl .class files are always kept on the classpath.
* | | | Removing unused code.Paul Phillips2013-10-0250-762/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Most of this was revealed via -Xlint with a flag which assumes closed world. I can't see how to check the assumes-closed-world code in without it being an ordeal. I'll leave it in a branch in case anyone wants to finish the long slog to the merge.
* | | | Remove 'hasDefaultFlag'.Paul Phillips2013-10-021-3/+3
| |_|/ |/| | | | | | | | | | | This is the change which broke the compiler until I made the changes found in 693ecffbaf.
* | | Merge pull request #3003 from paulp/pr/position-catchupPaul Phillips2013-10-019-46/+45
|\ \ \ | | | | | | | | Updating Position call sites.
| * | | Updating Position call sites.Paul Phillips2013-09-279-46/+45
| | | | | | | | | | | | | | | | | | | | | | | | Calling position factories rather than instantiating these particular classes. Not calling deprecated methods. Added a few position combinator methods.
* | | | Merge pull request #2991 from xeno-by/topic/unapply-copierEugene Burmako2013-09-301-36/+57
|\ \ \ \ | | | | | | | | | | transformers no longer ignore UnApply.fun
| * | | | refactors ToolBoxGlobal wrappersEugene Burmako2013-09-271-64/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Centralizes wrappers in a single location and makes it impossible to use the compiler without going through that location. Also fixes the option string tokenization bug that was there for ages. This time I figured out that there's already an implementation of the tokenizer in our compiler, so I just used it :)
| * | | | transformers no longer ignore UnApply.funEugene Burmako2013-09-261-25/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Second time's the charm. I remember trying to do exactly the same somewhen around 2.10.0-M4, but then some continuations tests were failing. Luckily, today everything went smoothly. Please note that this fix changes the way that SI-5465 manifests itself. Previously it produced type errors, now it simply crashes the compiler. Therefore I had to attach the try/catch FatalError clause to invocations of toolbox methods, so that compiler crashes get caught and translated to ToolBoxErrors. Also fixes SI-7871, and that clears the way for implementing quasiquotes with conventional macros rather than relying on a special case in typer.
* | | | | Some refinement of -Xlint interpolation warning.Paul Phillips2013-09-271-33/+30
| |/ / / |/| | | | | | | | | | | | | | | | | | | | | | | I had covered a few more cases working on this recently. The warnings in several more cases involving polymorphism, currying, and selects vs. idents receive more refined handling.
* | | | Merge pull request #2909 from soc/SI-7629-deprecate-view-boundsJason Zaugg2013-09-271-4/+6
|\ \ \ \ | | | | | | | | | | SI-7629 Deprecate view bounds
| * | | | SI-7629 Deprecate view boundsSimon Ochsenreither2013-09-251-4/+6
| |/ / / | | | | | | | | | | | | | | | | | | | | This introduces a warning(/error with -Xfuture) with a general migration advice. The IDE can use the warning to offer a quick fix with the specific refactoring necessary.
* | | | Merge pull request #2992 from retronym/ticket/7877Jason Zaugg2013-09-272-2/+3
|\ \ \ \ | | | | | | | | | | Only look for unapplies in term trees
| * | | | SI-7877 Only look for unapplies in term treesJason Zaugg2013-09-272-2/+3
| |/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since Scala 2.10.2, the enclosed test case has crashed in the backend. Before, we correctly rejected this pattern match. My bisection landed at a merge commit f16f4ab157, although both parents were good. So I don't quite trust that. I do think the regression stems from the changes to allow: case rx"AB(.+)" => Examples of this are in run/t7715.scala. This commit limits the search for extractors to cases where the function within the Apply is a term tree.
* | | | Merge pull request #2978 from som-snytt/issue/7848-forgotten-interp-msg-lgtmPaul Phillips2013-09-274-27/+35
|\ \ \ \ | | | | | | | | | | SI-7848 Xlint no warn on $sym with params
| * | | | SI-7848 Xlint no warn on $sym with paramsSom Snytt2013-09-234-27/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This idea brought to you by retronym. Also improve implicitNotFound detection at typer; and avoid checking the standard interpolation expression for cases like s"some $$x". Some minor refactorings of implicitNotFound strings. The intersobralator allows extra spaces, i.e., trims.
* | | | | Merge pull request #2996 from paulp/pr/3971Jason Zaugg2013-09-272-1/+14
|\ \ \ \ \ | | | | | | | | | | | | SI-3971 error message carat mispoints at curried methods.
| * | | | | SI-3971 error message carat mispoints at curried methods.Paul Phillips2013-09-272-1/+14
| | |_|_|/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Point at the beginning of the first argument list when reporting an error, as this is most easily associated with the application taking place (which may involve multiple applies in succession.) Thanks to retronym for figuring out why issuing a better error message broke the compiler on non-erroneous compile runs. The changes to "treesInResult" are the consequence.
* | | | | Merge pull request #2998 from paulp/pr/6120Paul Phillips2013-09-271-7/+18
|\ \ \ \ \ | | | | | | | | | | | | SI-6120 multiple warnings at same position.
| * | | | | SI-6120 multiple warnings at same position.Paul Phillips2013-09-271-7/+18
| |/ / / / | | | | | | | | | | | | | | | | | | | | An error suppresses all further warnings at the same position, but multiple warnings can be heard.
* | | | | Merge pull request #2987 from paulp/pr/emptySelfTypePaul Phillips2013-09-2716-28/+28
|\ \ \ \ \ | | | | | | | | | | | | SI-6762 rename emptyValDef to emptySelfType.
| * | | | | SI-6762 rename emptyValDef to noSelfType.Paul Phillips2013-09-2716-28/+28
| |/ / / / | | | | | | | | | | | | | | | | | | | | Looks like emptyValDef.isEmpty was already changed to return false, so now all that's left is a name which means something.
* | | | | Merge pull request #2995 from paulp/pr/defaultparamJason Zaugg2013-09-272-6/+4
|\ \ \ \ \ | | | | | | | | | | | | Fix up DEFAULTPARAM semantics.