summaryrefslogtreecommitdiff
path: root/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala
Commit message (Collapse)AuthorAgeFilesLines
* SI-8703 add support for blocks with just a single expression to quasiquotesDenys Shabalin2014-07-021-0/+7
| | | | | | | | | | | | | | | | | Previously it was impossible to match a block that was constructed as Block(Nil, term) Due to the fact that quasiquotes always flatten those into just term. This is a correct behaviour for construction (for sake of consistency with parser) but doing it in deconstruction mode make it impossible to match such blocks which could have been constructed manually somewhere. To fix this we just disable block flattening in deconstruction mode. Interestingly enough this doesn't break existing code due to the fact that quasiquote's block matcher also matches expressions as single-element blocks. This allows to match single-element blocks with patterns like q"{ $foo }".
* SI-8387 don't match new as a function applicationDenys Shabalin2014-03-251-0/+7
|
* SI-8350 treat single parens equivalently to no-parens in newDenys Shabalin2014-03-251-0/+17
| | | | | q"new C" and q"new C()" have identical trees after parsing. This commit adds knowledge of this invariant to SyntacticNew.
* Add more tests for partial functionsDenys Shabalin2014-03-101-0/+5
|
* SI-8366 make partial function and match trees disjointDenys Shabalin2014-03-101-0/+6
| | | | | | | | | | | | | | | | Previously one could match a partial function with match quasiquote: scala> val q"$scrutinee match { case ..$cases }" = q"{ case Foo => Bar }" scrutinee: universe.Tree = <empty> cases: List[universe.CaseDef] = List(case Foo => Bar) This was quite annoying as it leaked encoding of partial functions as Match trees with empty tree in place of scrutinee. This commit make sure that matches and partial functions are disjoint and don't match one another (while preserving original encoding under the hood out of sight of the end user.)
* SI-8331 make sure type select & applied type doesn't match termsDenys Shabalin2014-03-091-0/+12
| | | | | | Due to tree re-use it used to be the fact that type quasiquotes could match term trees. This commit makes sure selections and applied type and type applied are all non-overlapping between q and tq.
* Fix block construction/deconstruction asymmetryDenys Shabalin2014-02-281-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | Deconstruction of blocks in case clauses uncovered asymmetry between construction and deconstruction of blocks: tree match { case cq"$pat => ..$cases" => cq"$pat => ..$cases" } Such an identity-like transformation used to produce an incorrect tree due to the fact that zero-element block was mistakingly associated with empty tree. Such association was used as a solution to block flatenning: val ab = q"a; b" q"..$ab; c" // ==> q"a; b; c" val a = q"a" q"..$a; c" // ==> q"a; c" val empty = q"" q"..$empty; c" // ==> q"c" This commit changes meaning of zero-element block to a be a synthetic unit instead. This is consistent with parsing of `{}`, cases, ifs and non-abstract empty-bodied methods. A local tweak to block flattenning is used to flatten empty tree as empty list instead.
* SI-8275 allow to directly extract block contents of the case defDenys Shabalin2014-02-281-0/+11
| | | | | Due to the fact that blocks in cases are implicit one might expect to be able to extract its contents with `..$`.
* Make handling of tuples more consistent in quasi-quotesDenys Shabalin2014-02-101-0/+5
| | | | | | | | | | | | | | On one hand we know that q"($expr)" is the same as q"$expr". On the other if we wrap it into a list and splice as q"(..$expr)" we get a Tuple1 constructor call which is inconsistent. This pull request fixes this inconsistency by making q"(..$expr)" being equivalent q"(${expr.head})" for single-element list. We also add support for matching of expressions as single-element tuples (similarly to blocks) and remove liftables and unliftables for Tuple1 (which aren't clearly defined any longer due to q"(foo)" == q"foo" invariant).
* SI-8173 add support for patterns like init :+ last to quasiquotesDenys Shabalin2014-02-021-6/+47
| | | | | | | | | | | | Adds support for patterns like: val q"{ ..$init; $last }" = q"{ a; b; c }" // init == List(q"a", q"b") // last == q"c" Which under the hood get compiled as `:+` patterns: SyntacticBlock(init :+ last)
* SI-8008 Make q”f(..$xs)” only match trees with Apply nodeDen Shabalin2013-12-101-2/+4
| | | | | | | | | | Previously it also matched other nodes but returned Nil as value of xs. This behavior was added for sake of consistentcy with q”f[..$ts]”. On the other hand q”f[..$Nil]” == q”f” but q”f(..$Nil)” == q”f()” not q”f”. Due to this deconstruction/construction symmetry was broken. On the other hand applications also have q"f(...$xss)" option which is infact similar to q"f[..$ts]". Splicing Nil into it also results in q"f".
* simplify imports in quasiquotes scalacheck testsDen Shabalin2013-11-121-7/+2
|
* make q"f(..$xs)" deconstruction symmetrical to q"f[..$xs]"Den Shabalin2013-10-181-3/+2
|
* advanced fresh name reificationDen Shabalin2013-10-181-1/+23
| | | | | | | | | | During parsing some names are generated artificially using freshTermName & freshTypeName (e.g. `x$1`). Such names should be reified in a different way because they are assumed to be always fresh and non-overlapping with the environment. So `x$1` should reify down to equivalent of `freshTermName("x$")` rather than `TermName("x$1")`. But this is not enough. One name can be used more than once in a tree. E.g. `q"_ + 1"` desugars into `q"x$1 => x$1 + 1"`. So we need to ensure that every place where `x$1` is used gets the same fresh name. Hence the need for `withFreshTermName` that lets q"_ + 1" quasiquote desugare into equivalent of `withFreshTermName("x$") { freshx => q"$freshx => $freshx + 1" }`. For pattern quasiquotes it's a bit different. Due to the fact that end-result must be a pattern we need to represent fresh names as patterns too. A natural way to express that something is fresh is to represent it as a free variable (e.g. any name will do in that place). But due to possible use of the same name in multiple places we need to make sure that all such places have the same values by adding a sequence of guards to the pattern. Previously such names were reified naively and it could have caused name collision problems and inability to properly much on trees that contain such names.
* add syntactic extractor for assignment-like treesDen Shabalin2013-09-181-0/+20
| | | | | | | | | | | There are three kinds of assign-like trees: 1. Assign(lhs, rhs) // $lhs = $rhs 3. AssignOrNamedArg(lhs, rhs) // $lhs = $rhs 2. Apply(Select(f, nme.update), args :+ rhs) // $f(..$args) = $rhs New syntactic combinator unifies all of them and lets users not to think about these implementations details.
* SI-7723 better support for deconstruction of new expressionsDen Shabalin2013-09-051-0/+17
|
* SI-7803 support for matching of anonymous function literalsDen Shabalin2013-09-051-1/+8
|
* refine block and applied/typeapplied splicing/matching semanticsDen Shabalin2013-09-051-0/+5
| | | | | | | | | | | | | | | | | | | 1. blocks now match single term-level expressions to account for automatic block elimination. E.g. val q"{ ..$stats }" = q"foo" will match into stats = List(q"foo"). This is useful to uniformly deal with blocks on term level. 2. blocks in quasiquotes collapse into single expressions 3. Applied and TypeApplied now have constructors too which helps to unify matching and extraction in quasiquote reifier 4. TypeApplied now matches AppliedTypeTree too 5. Add Syntactic prefix to Applied and TypeApplied
* refactor definition tests into separate subsuiteDen Shabalin2013-09-051-57/+0
|
* tests for quasiquotesDen Shabalin2013-07-081-0/+122
Introduces an extensive ScalaCheck-based test suite for recently implemented quasiquotes. Provides tools for syntactic tree comparison and verifying compilation error messages.