Skip to content

Commit 43d2082

Browse files
committed
Remove regex hack
1 parent c23d4c5 commit 43d2082

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2838,7 +2838,7 @@ object Parsers {
28382838
*/
28392839
def namedPattern(location: Location = Location.InPattern): Tree =
28402840
// TODO: Figure out the performance impact of this lookahead
2841-
if (in.token == IDENTIFIER && in.lookahead.token == EQUALS)
2841+
if ((in.token == IDENTIFIER || in.token == BACKQUOTED_IDENT) && in.lookahead.token == EQUALS) then
28422842
val ident = termIdent()
28432843
accept(EQUALS)
28442844
NamedArg(ident.name, pattern(location))

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,10 +1413,15 @@ trait Applications extends Compatibility {
14131413

14141414
val positionOfStringNames: Map[String, Int] =
14151415
if names.exists then
1416-
// TODO: Don't use regular expression to deconstruct tuples
1417-
val reg = "\"([^\"]+)\"".r
1418-
reg.findAllMatchIn(names.showDcl)
1419-
.map(_.group(1))
1416+
// TODO: why doesn't names.info.dealias works?
1417+
def dealias(typ: Type): Type = typ match
1418+
case alias: TypeAlias => alias.alias
1419+
case other => other
1420+
1421+
dealias(names.info)
1422+
// TODO: Error handling if Names is malformed
1423+
.tupleElementTypes.getOrElse(Nil)
1424+
.map { case ConstantType(Constant(name: String)) => name }
14201425
.zipWithIndex
14211426
.toMap
14221427
// TODO: The test should actually be: is unapplyFn generated by the compiler because we have a case class?

tests/pos/namedPatternMatching.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Age:
1010
Some(age.hidden.asInstanceOf)
1111

1212
object StringExample:
13-
def unapply(str: String): Option[(Char, Char) & { type Names = "first" *: "last" *: EmptyTuple }] =
13+
def unapply(str: String): (Char, Char) & { type Names = "first" *: "\"" *: EmptyTuple } =
1414
Some((str.head, str.last)).asInstanceOf
1515

1616
case class User(name: String, age: Age, city: String)
@@ -27,7 +27,7 @@ val User(name = name, age = Age(years = years)) = user
2727

2828
// partial function
2929
val maybeTom = Some(user).collect {
30-
case u @ User(name = StringExample(last = 'm')) => u
30+
case u @ User(name = StringExample(`"` = 'm')) => u
3131
}
3232

3333
val berlinerNames = for

0 commit comments

Comments
 (0)