aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Commit message (Collapse)AuthorAgeFilesLines
* Revert <: Product requierment in pattern matchingOlivier Blanvillain2017-04-131-1/+1
| | | | | | | | | | | | | | | The change in question broke the following pattern, commonly used in name based pattern matching: ```scala object ProdEmpty { def _1: Int = ??? def _2: String = ??? def isEmpty = true def get = this } ``` This type define both `_1` and `get` + `isEmpty` (but is not <: Product). After #1938, `ProdEmpty` became eligibles for both product and name based pattern. Because "in case of ambiguities, *Product Pattern* is preferred over *Name Based Pattern*", isEmpty wouldn't be used, breaking the scalac semantics.
* Merge pull request #1938 from dotty-staging/named-based-patmatFelix Mulder2017-04-111-2/+2
|\ | | | | Change case class desugaring and decouple Products and name-based-pattern-matching
| * Move isProductSubType to Applications & rename to canProductMatchOlivier Blanvillain2017-04-111-1/+1
| |
| * Decouple Product and pattern-matchingOlivier Blanvillain2017-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Product pattern use to: - have a `<: Product` requirement - compute the arity of a pattern by looking at `N` in a `ProductN` superclass. This commit changes `<: Product`, instead we look for a `_1` member. The arity is determined by inspecting `_1` to `_N` members instead. --- Here another attempt to formalize Dotty's pattern-matching (base on #1805). This covers the *Extractor Patterns* [section of the spec](https://www.scala-lang.org/files/archive/spec/2.12/08-pattern-matching.html#extractor-patterns). Dotty support 4 different extractor patterns: Boolean Pattern, Product Pattern, Seq Pattern and Name Based Pattern. Boolean Pattern - Extractor defines `def unapply(x: T): Boolean` - Pattern-matching on exactly `0` patterns Product Pattern - Extractor defines `def unapply(x: T): U` - `N > 0` is the maximum number of consecutive (parameterless `def` or `val`) `_1: P1` ... `_N: PN` members in `U` - Pattern-matching on exactly `N` patterns with types `P1, P2, ..., PN` Seq Pattern - Extractor defines `def unapplySeq(x: T): U` - `U` has (parameterless `def` or `val`) members `isEmpty: Boolean` and `get: S` - `S <: Seq[V]` - Pattern-matching on any number of pattern with types `V, V, ..., V` Name Based Pattern - Extractor defines `def unapply(x: T): U` - `U` has (parameterless `def` or `val`) members `isEmpty: Boolean` and `get: S` - If there is exactly `1` pattern, pattern-matching on `1` pattern with type `S` - Otherwise fallback to Product Pattern on type `U` In case of ambiguities, *Product Pattern* is preferred over *Name Based Pattern*.
* | Rename NameExtractor -> NameKindMartin Odersky2017-04-111-3/+3
| |
* | Make freshName semanticMartin Odersky2017-04-111-12/+12
|/
* Harmonize paramTypes and paramBoundsMartin Odersky2017-04-061-1/+1
| | | | | | MethodTypes have paramTypes whereas PolyTypes have paramBounds. We now harmonize by alling both paramInfos, and parameterizing types that will become common to both.
* Merge pull request #2157 from dotty-staging/patmat-dead-codeFelix Mulder2017-04-021-109/+3
|\ | | | | Remove dead code in pattern matching
| * Remove unreachable `tupleExtractor` methodOlivier Blanvillain2017-03-301-22/+1
| |
| * Remove dead code from pattern matcherOlivier Blanvillain2017-03-301-87/+2
| | | | | | | | Starting from unreachable case https://github.com/lampepfl/dotty/blob/f75caad00256db52bbd3310f245e51d23c2a76cc/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala#L1408
* | PatMat, Outerchecks: Check outers for selections from singleton type.Dmitry Petrashko2017-03-301-3/+4
| | | | | | | | | | Otherwise checks are done also on type projections. Same pitfall as https://issues.scala-lang.org/browse/SI-7214
* | PatMat: get rid of unnecessary forwarderDmitry Petrashko2017-03-301-8/+2
| |
* | Fix #2165, emit outerChecks on ThisTypeDmitry Petrashko2017-03-301-2/+2
|/ | | | | | ThisType doesn't have a termSymbol. And the check is actually too strong, and not needed.
* Remove uses of Collections from scala-reflectGuillaume Martres2017-03-081-4/+2
|
* Represent untyped operators as Ident instead of NameGuillaume Martres2017-02-051-2/+0
| | | | | | | | This has two advantages: - We can distinguish BackquotedIdent from Ident, allowing the user to use a defined "type `&`", see testcase. - We get better positions for the operators. This is useful in IDEs, for example to get the type at point.
* Implement new rules for name-based pattern matchingMartin Odersky2016-12-151-4/+5
| | | | This implements the rules laid down in #1805.
* Change by-name pattern matching.Martin Odersky2016-12-141-33/+27
| | | | New implementation following the scheme outlined in #1790.
* Move compiler and compiler tests to compiler dirFelix Mulder2016-11-221-0/+1989