summaryrefslogtreecommitdiff
path: root/test/files/neg
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #2852 from retronym/ticket/1980-warningAdriaan Moors2013-08-213-0/+22
|\ | | | | SI-1980 A lint warning for by-name parameters in right assoc methods
| * SI-1980 A lint warning for by-name parameters in right assoc methodsJason Zaugg2013-08-193-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The desugaring of right associative calls happens in the parser. This eagerly evaluates the arguments (to preserve left-to-right evaluation order the arguments are evaluated before the qualifier). This is pretty surprising if the method being called has a by-name parameter in the first parameter section. This commit adds a warning under -Xlint when defining such a method. The relevent spec snippets: > SLS 4.6.1 says that call-by-name argument "is not evaluated at the point of function application, but instead is evaluated at each use within the function". > > But 6.12.3 offers: > "If op is right- associative, the same operation is interpreted as { val x=e1; e2.op(x ) }, where x is a fresh name."
* | Merge pull request #2810 from xeno-by/topic/compile-time-onlyAdriaan Moors2013-08-214-0/+128
|\ \ | | | | | | @compileTimeOnly: moved to scala-library.jar, got some fixes
| * | @compileTimeOnly now works for symbols from the empty packageEugene Burmako2013-08-151-1/+22
| | | | | | | | | | | | Looks like we've got the entire language covered now.
| * | @compileTimeOnly now works for annotationsEugene Burmako2013-08-151-1/+10
| | | | | | | | | | | | | | | http://docs.scala-lang.org/overviews/macros/annotations.html say sincere "thank you!".
| * | marks Expr.splice and Expr.value with @compileTimeOnlyEugene Burmako2013-08-152-0/+22
| | | | | | | | | | | | | | | Now that @compileTimeOnly is part of the standard library, why don't we use it within the standard library.
| * | moves compileTimeOnly to scala-libraryEugene Burmako2013-08-142-0/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is the notion that's come to be universally useful, so I suggest we promote it to be universally accessible. Note that the attached test incorrectly fails to report errors for definitions coming from the empty package and for annotations. These are bugs, and they are fixed in subsequent commits of this pull request.
* | | Merge branch 'master' into patmatPaul Phillips2013-08-2014-10/+51
|\ \ \ | | | | | | | | | | | | | | | | | | | | Conflicts: src/compiler/scala/tools/nsc/Global.scala src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
| * \ \ Merge pull request #2840 from retronym/ticket/7756-2.11Adriaan Moors2013-08-195-0/+30
| |\ \ \ | | | | | | | | | | SI-7756 Uncripple refchecks in case bodies
| | * | | SI-7756 Uncripple refchecks in case bodiesJason Zaugg2013-08-165-0/+30
| | |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In 65340ed4ad2e, parts of RefChecks were disabled when we traversed into the results of the new pattern matcher. Similar logic existed for the old pattern matcher, but in that case the Match / CaseDef nodes still existed in the tree. The new approach was too broad: important checks no longer scrutinized the body of cases. This commit turns the checks back on when it finds the remnants of a case body, which appears as an application to a label def.
| * | | Merge pull request #2854 from som-snytt/issue/7729-slashAdriaan Moors2013-08-195-10/+10
| |\ \ \ | | | | | | | | | | SI-7729 Fix broken windows build
| | * | | SI-7729 Fix broken windows buildSom Snytt2013-08-195-10/+10
| | | |/ | | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixing #ifdiff uncovered a latent bug in partest when it detects paths to normalize in test log output. It would not normalize file separators for test names with non-word characters. This commit normalizes the test name to the ticket number as a workaround until the next partest version is picked up. It also fixes partest in this repo in case we've not yet switched over to the new repo. A separate PR will be submitted to the new repo as necessary.
| * | | Merge pull request #2839 from densh/topic/si-7757Adriaan Moors2013-08-194-0/+11
| |\ \ \ | | |/ / | |/| | SI-7757 disallow constructor annotations on traits
| | * | SI-7757 add additional test case with annotation on the next lineDen Shabalin2013-08-165-4/+10
| | | |
| | * | SI-7757 disallow constructor annotations on traitsDen Shabalin2013-08-162-0/+5
| | |/ | | | | | | | | | | | | | | | Previously it was possible to define constructor annotations on traits with really weird side-effects (parser lost the body of the trait). Now constructor annotations on traits will cause appropriate syntax errors.
* | | Refined name-based patmat methods.Paul Phillips2013-08-181-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | This fleshes out some of the slightly unfinished corners of the adventure, especially for unapplySeq. There's still an unhealthy amount of duplication and a paucity of specification, but I think it's in eminently good shape for a milestone.
* | | SI-5903 extractor macrosEugene Burmako2013-08-1815-0/+189
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Establishes a pattern that can be used to implement extractor macros that give the programmer control over signatures of unapplications at compile-time. === The pattern === In a nutshell, given an unapply method (for simplicity, in this example the scrutinee is of a concrete type, but it's also possible to have the extractor be polymorphic, as demonstrated in the tests): ``` def unapply(x: SomeType) = ??? ``` One can write a macro that generates extraction signatures for unapply on per-call basis, using the target of the calls (c.prefix) and the type of the scrutinee (that comes with x), and then communicate these signatures to the typechecker. For example, here's how one can define a macro that simply passes the scrutinee back to the pattern match (for information on how to express signatures that involve multiple extractees, visit https://github.com/scala/scala/pull/2848). ``` def unapply(x: SomeType) = macro impl def impl(c: Context)(x: c.Tree) = { q""" new { class Match(x: SomeType) { def isEmpty = false def get = x } def unapply(x: SomeType) = new Match(x) }.unapply($x) """ } ``` In addition to the matcher, which implements domain-specific matching logic, there's quite a bit of boilerplate here, but every part of it looks necessary to arrange a non-frustrating dialogue with the typer. Maybe something better can be done in this department, but I can't see how, without introducing modifications to the typechecker. Even though the pattern uses structural types, somehow no reflective calls are being generated (as verified by -Xlog-reflective-calls and then by manual examination of the produced code). That's a mystery to me, but that's also good news, since that means that extractor macros aren't going to induce performance penalties. Almost. Unfortunately, I couldn't turn matchers into value classes because one can't declare value classes local. Nevertheless, I'm leaving a canary in place (neg/t5903e) that will let us know once this restriction is lifted. === Use cases === In particular, the pattern can be used to implement shapeshifting pattern matchers for string interpolators without resorting to dirty tricks. For example, quasiquote unapplications can be unhardcoded now: ``` def doTypedApply(tree: Tree, fun0: Tree, args: List[Tree], ...) = { ... fun.tpe match { case ExtractorType(unapply) if mode.inPatternMode => // this hardcode in Typers.scala is no longer necessary if (unapply == QuasiquoteClass_api_unapply) macroExpandUnapply(...) else doTypedUnapply(tree, fun0, fun, args, mode, pt) } } ``` Rough implementation strategy here would involve writing an extractor macro that destructures c.prefix, analyzes parts of StringContext and then generates an appropriate matcher as outlined above. === Implementation details === No modifications to core logic of typer or patmat are necessary, as we're just piggybacking on https://github.com/scala/scala/pull/2848. The only minor change I introduced is a guard against misbehaving extractor macros that don't conform to the pattern (e.g. expand into blocks or whatever else). Without the guard we'd crash with an NPE, with the guard we get a sane compilation error.
* | | New tests for name-based pattern matcher.Paul Phillips2013-08-175-0/+226
| | |
* | | Pattern matcher: extractors become name-based.Paul Phillips2013-08-175-19/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An extractor is no longer required to return Option[T], and can instead return anything which directly contains methods with these signatures: def isEmpty: Boolean def get: T If the type of get contains methods with the names of product selectors (_1, _2, etc.) then the type and arity of the extraction is inferred from the type of get. If it does not contain _1, then it is a single value extractor analogous like Option[T]. This has significant benefits and opens new territory: - an AnyVal based Option-like class can be used which leverages null as None, and no allocations are necessary - for primitive types the benefit is squared (see below) - the performance difference between case classes and extractors should now be largely eliminated - this in turn allows us to recapture great swaths of memory which are currently squandered (e.g. every TypeRef has fields for pre and args, even though these are more than half the time NoPrefix and Nil) Here is a primitive example: final class OptInt(val x: Int) extends AnyVal { def get: Int = x def isEmpty = x == Int.MinValue // or whatever is appropriate } // This boxes TWICE: Int => Integer => Some(Integer) def unapply(x: Int): Option[Int] // This boxes NONCE def unapply(x: Int): OptInt As a multi-value example, after I contribute some methods to TypeRef: def isEmpty = false def get = this def _1 = pre def _2 = sym def _3 = args Then it's extractor becomes def unapply(x: TypeRef) = x Which, it need hardly be said, involves no allocations.
* | | SI-4425 do some validity checking on unapplies.Paul Phillips2013-08-173-1/+95
|/ / | | | | | | | | | | Filter out unapplies which can't be called (such as those with a second non-implicit parameter list) and report the error in a meaningful fashion.
* | Merge pull request #2830 from densh/topic/stats-parsing-2Adriaan Moors2013-08-162-0/+47
|\ \ | | | | | | updated SI-7331, SI-6843, SI-7731, parser entry point refactoring, assertThrows utility function
| * | SI-6843 well-positioned syntax errors for quasiquotesDen Shabalin2013-08-142-0/+47
| |/ | | | | | | | | | | | | | | | | | | | | | | | | This is achieved in a following way: 1. Similarly to toolbox quasiquotes can go away with wrapping for parsing purpose after introduction of `parseStats` and `parseRule` entry points. 2. In case of syntax error quasiquote computes equivalent corresponding position in the source code with the help of `corrrespondingPosition` mapper which relies on position data collected into `posMap` during code generation.
* | Merge pull request #2823 from som-snytt/issue/7715Adriaan Moors2013-08-162-0/+31
|\ \ | | | | | | SI-7715 String inpatternation s"$_" for s"${_}"
| * | SI-7715 String inpatternation s"$_" for s"${_}"Som Snytt2013-08-122-0/+31
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In a pattern, ``` scala> implicit class RX(val sc: StringContext) { | def rx = sc.parts.mkString("(.+)").r } defined class RX scala> "2 by 4" match { case rx"$a by $_" => a } res0: String = 2 scala> val rx"$_ by $b" = "2 by 4" b: String = 4 ```
* / SI-7544 Interpolation message for %% literalSom Snytt2013-08-061-5/+5
|/ | | | | | | | | | | The new error text: "conversions must follow a splice; use %% for literal %, %n for newline". The error is emitted when % is not at the start of a part; only the non-conversions %% and %n are allowed. It would be nice if it were convenient to parse the part to see what the user may have intended, but c'est l'erreur.
* Merge remote-tracking branch 'scala/master' into merge-2.10.xGrzegorz Kossakowski2013-07-2911-22/+27
|\
| * Merge pull request #2746 from soc/topic/paulp-typer-debug-outputAdriaan Moors2013-07-2910-20/+25
| |\ | | | | | | Improve type printing (toString/debugging)
| | * Make -Ytyper-debug output readable.Paul Phillips2013-07-178-15/+17
| | |
| | * Cleanups in type printing.Paul Phillips2013-07-173-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | More consistency as to how to understand aliases, singletons, specialized symbols, subclasses. Fewer weird special casings, like normalizing tuples and functions during type printing, but nothing else. I avoid "normalize" entirely now, and do not make special cases for dealiasing, which is already well handled when printing error messages. Look at the change to test/files/neg/t2641.check to get a sense of why we should resist calling normalize during the early days of a compilation run. Anonymous and refinement classes can be printed far more usefully by revealing their parents, and that too is here. Hardened toString against undesirable side effects. Make toString final to discourage any further rogue toString overriders. Make safeToString a little safer.
* | | Merge remote-tracking branch 'scala/2.10.x' into merge-2.10.xGrzegorz Kossakowski2013-07-295-18/+38
|\ \ \ | |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: bincompat-backward.whitelist.conf bincompat-forward.whitelist.conf src/compiler/scala/reflect/reify/phases/Reshape.scala src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala src/compiler/scala/tools/nsc/transform/Mixin.scala src/compiler/scala/tools/nsc/typechecker/RefChecks.scala src/compiler/scala/tools/nsc/typechecker/Typers.scala src/library/scala/concurrent/impl/Promise.scala src/reflect/scala/reflect/internal/StdAttachments.scala test/files/neg/macro-override-macro-overrides-abstract-method-b.check test/files/run/t7569.check
| * | Rename t7636-neg.check to the standard t7636.check.Adriaan Moors2013-07-291-0/+0
| | | | | | | | | | | | Not sure which partest bug allowed this, but the old name was wrong.
| * | Merge pull request #2738 from retronym/ticket/7636Grzegorz Kossakowski2013-07-272-0/+17
| |\ \ | | | | | | | | SI-7636 Fix a NPE in typing class constructors
| | * | SI-7636 Fix a NPE in typing class constructorsChristopher Vogt2013-07-162-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | If we encountered an erroneous super call due to a failure in parent type argument inference, we must avoid inspecting the untyped children of erroneous trees.
| * | | SI-7657 clarifies the "macro overrides method" ruleEugene Burmako2013-07-143-18/+21
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently we allow macros to override non-abstract methods (in order to provide performance enhancements such as foreach for collections), and we also disallow macros to override abstract methods (otherwise downcasting might lead to AbstractMethodErrors). This patch fixes an oversight in the disallowing rule that prohibited macros from overriding a concrete method if that concrete method itself overrides an abstract method. RefCheck entertains all overriding pairs, not only the immediate ones, so the disallowing rule was triggered. Now macros can override abstract methods if and only if either the base type or the self type contain a matching non-abstract method.
* | | Merge pull request #2737 from retronym/ticket/7669Adriaan Moors2013-07-295-2/+23
|\ \ \ | | | | | | | | SI-7669 Fix exhaustivity warnings for recursive ADTs.
| * | | SI-7669 Fix exhaustivity warnings for recursive ADTs.Jason Zaugg2013-07-175-2/+23
| | |/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pattern matcher's analysis was correctly finding models under which the match in the enclosed test could fail. But, when trying to render that model as a counter example, it ran into an internal inconsistency and gave up. That inconsistency arose from VariableAssignment, which: > turn the variable assignments into a tree > the root is the scrutinee (x1), edges are labelled > by the fields that are assigned a node is a variable > example (which is later turned into a counter example) In the process, it notes the unreachable case `V2 = NotHandled`, which can only arise if `V1 = Op`, ie the scrutinee is `Op(NotHandled())`. V2 is assosicated with the path `x1.arg`. The code then looked for any variable assosicated with the prefix `x1` and registered that its field `arg` was assosicated with this variable assignment. However, the assignment for `V1 = NotHandled` (another missing case) is also associated with the path `x1`. Registering this field makes no sense here; we should only do that for `Op`. This commit conditionally registers the fields based on the class of `VariableAssignment#cls`. We no longer hit the inconsistency in `VariableAssignment#allFieldAssignmentsLegal`. This favourably changes the results of two existing tests. I had to tweak the counter example pruning to avoid relying on CounterExample.==, which is flaky in the light of Nil and List(). It is possible to have: A, B where A != B && A.coveredBy(B) && B.coveredBy(A) Luckily it is straightforward to implement pruning entirely with coveredBy.
* | | Merge pull request #2690 from soc/SI-7620Adriaan Moors2013-07-296-49/+2
|\ \ \ | | | | | | | | SI-7620 Remove floating-point-literals-without-digit-after-dot
| * | | SI-7620 Remove floating-point-literals-without-digit-after-dotSimon Ochsenreither2013-06-286-49/+2
| | | |
* | | | SI-7695 Macro debug output on -explaintypesSom Snytt2013-07-275-0/+29
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | It looks like checkConforms should wait for error before using explainTypes, rather than turning on macro debug trace if explaintypes is set. In particular, macro debug output is Console.println instead of reporter.echo or similar, so partest can't test it.
* | | Merge pull request #2714 from scalamacros/topic/quasiquotesAdriaan Moors2013-07-103-0/+27
|\ \ \ | | | | | | | | Quasiquotes
| * | | macro impls can now return subtypes of c.TreeEugene Burmako2013-07-103-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 10229316db allowed macro impls to take and return values of type c.Tree in addition to the usual c.Expr. However it didn't take into account that it is often useful to return subtypes of trees (e.g. with quasiquotes that expand into expressions typed as precisely as possible). This patch fixes that oversight.
* | | | Merge pull request #2717 from retronym/ticket/6574Adriaan Moors2013-07-102-0/+17
|\ \ \ \ | | | | | | | | | | SI-6574 Support @tailrec for extension methods.
| * | | | SI-6574 Support @tailrec for extension methods.Jason Zaugg2013-07-102-0/+17
| | |/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, when the body of an extension method is transplanted to the companion object, recursive calls point back to the original instance method. That changes during erasure, but this is too late for tail call analysis/elimination. This commit eagerly updates the recursive calls to point to the extension method in the companion. It also removes the @tailrec annotation from the original method.
* | | | Merge pull request #2650 from paulp/issue/6221Adriaan Moors2013-07-083-7/+12
|\ \ \ \ | |_|/ / |/| | | SI-6221 inference with Function1 subtypes.
| * | | SI-6221 inference with Function1 subtypes.Paul Phillips2013-06-133-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There appears to be no upper bound on the number of places we have to remove calls to typeSymbol and introduce calls to baseType. This one was type inference for function parameter types: worked when expected type was A => B, but not if there was an implicit conversion from A => B to the expected type.
* | | | Merge pull request #2694 from adriaanm/masterGrzegorz Kossakowski2013-07-012-7/+5
|\ \ \ \ | | | | | | | | | | Merge 2.10.x into master
| * \ \ \ Merge 2.10.x into masterAdriaan Moors2013-06-282-7/+5
| |\ \ \ \ | | |_|/ / | |/| | / | | | |/ | | |/| | | | | | | | | Conflicts: src/compiler/scala/tools/nsc/typechecker/Duplicators.scala src/library/scala/concurrent/Future.scala test/files/jvm/scala-concurrent-tck.scala
| | * | SI-7571 Allow nesting of anonymous classes in value classesJason Zaugg2013-06-192-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 5d9cde105e added deep prohibition of nested classes within a value class. This has the undesirable side effect of prohibiting partial functions literals in method bodies of a value class. The intention of that prohibition was to avoid problems in code using Type Tests, such as: class C(val inner: A) extends AnyVal { class D } def foo(a: Any, other: C) = a match { case _ : other.D } Here, the pattern usually checks that `a.$outer == other`. But that is incongruent with the way that `other` is erased to `A`. However, not all nested classes could lead us into this trap. This commit slightly relaxes the restriction to allow anonymous classes, which can't appear in a type test. The test shows that the translation generates working code.
* | | | Merge pull request #2620 from magarciaEPFL/backendish33Adriaan Moors2013-07-014-1/+26
|\ \ \ \ | |/ / / |/| | | new bytecode emitter, GenBCode (11th attempt)
| * | | more informative name for backend-selection via command-lineMiguel Garcia2013-06-272-2/+2
| | | |