Skip to content

Commit 886b2a1

Browse files
committed
Add new pattern matcher
1 parent c6076a0 commit 886b2a1

File tree

7 files changed

+538
-0
lines changed

7 files changed

+538
-0
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Compiler {
6363
new HoistSuperArgs, // Hoist complex arguments of supercalls to enclosing scope
6464
new ClassOf), // Expand `Predef.classOf` calls.
6565
List(new TryCatchPatterns, // Compile cases in try/catch
66+
new PatMat,
6667
new PatternMatcher, // Compile pattern matches
6768
new ExplicitOuter, // Add accessors to outer classes from nested ones.
6869
new ExplicitSelf, // Make references to non-trivial self types explicit as casts

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
682682
def select(name: Name)(implicit ctx: Context): Select =
683683
Select(tree, name)
684684

685+
/** A select node with the given selector name such that the designated
686+
* member satisfies predicate `p`. Useful for disambiguating overloaded members.
687+
*/
688+
def select(name: Name, p: Symbol => Boolean)(implicit ctx: Context): Select =
689+
select(tree.tpe.member(name).suchThat(p).symbol)
690+
685691
/** A select node with the given type */
686692
def select(tp: NamedType)(implicit ctx: Context): Select =
687693
untpd.Select(tree, tp.name).withType(tp)

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ object Printers {
3232
val pickling: Printer = noPrinter
3333
val inlining: Printer = noPrinter
3434
val exhaustivity: Printer = noPrinter
35+
val patmatch: Printer = new Printer
3536
val simplify: Printer = noPrinter
3637
}

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ class Definitions {
373373
def Seq_apply(implicit ctx: Context) = Seq_applyR.symbol
374374
lazy val Seq_headR = SeqClass.requiredMethodRef(nme.head)
375375
def Seq_head(implicit ctx: Context) = Seq_headR.symbol
376+
lazy val Seq_dropR = SeqClass.requiredMethodRef(nme.drop)
377+
def Seq_drop(implicit ctx: Context) = Seq_dropR.symbol
378+
lazy val Seq_lengthCompareR = SeqClass.requiredMethodRef(nme.lengthCompare)
379+
def Seq_lengthCompare(implicit ctx: Context) = Seq_lengthCompareR.symbol
376380

377381
lazy val ArrayType: TypeRef = ctx.requiredClassRef("scala.Array")
378382
def ArrayClass(implicit ctx: Context) = ArrayType.symbol.asClass

0 commit comments

Comments
 (0)