Skip to content

Commit 7e5070e

Browse files
committed
Add quotes to strings in tasty extractors
To make pattern matches mach the exact names or strings
1 parent a0ddf50 commit 7e5070e

7 files changed

+194
-194
lines changed

library/src/scala/tasty/util/TastyPrinter.scala

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class TastyPrinter[T <: Tasty with Singleton](val tasty: T) {
2828

2929
def visitTree(x: Tree): Buffer = x match {
3030
case Term.Ident(name) =>
31-
this += "Ident(" += name += ")"
31+
this += "Ident(\"" += name += "\")"
3232
case Term.Select(qualifier, name, signature) =>
33-
this += "Select(" += qualifier += ", " += name += ", " += signature += ")"
33+
this += "Select(" += qualifier += ", \"" += name += "\", " += signature += ")"
3434
case Term.This(qual) =>
3535
this += "This(" += qual += ")"
3636
case Term.Super(qual, mix) =>
@@ -46,7 +46,7 @@ class TastyPrinter[T <: Tasty with Singleton](val tasty: T) {
4646
case Term.Typed(expr, tpt) =>
4747
this += "Typed(" += expr += ", " += tpt += ")"
4848
case Term.NamedArg(name, arg) =>
49-
this += "NamedArg(" += name += ", " += arg += ")"
49+
this += "NamedArg(\"" += name += "\", " += arg += ")"
5050
case Term.Assign(lhs, rhs) =>
5151
this += "Assign(" += lhs += ", " += rhs += ")"
5252
case Term.Block(stats, expr) =>
@@ -66,20 +66,20 @@ class TastyPrinter[T <: Tasty with Singleton](val tasty: T) {
6666
case Term.Inlined(call, bindings, expansion) =>
6767
this += "Inlined(" += call += ", " ++= bindings += ", " += expansion += ")"
6868
case ValDef(name, tpt, rhs) =>
69-
this += "ValDef(" += name += ", " += tpt += ", " += rhs += ")"
69+
this += "ValDef(\"" += name += "\", " += tpt += ", " += rhs += ")"
7070
case DefDef(name, typeParams, paramss, returnTpt, rhs) =>
71-
this += "DefDef(" += name += ", " ++= typeParams += ", " +++= paramss += ", " += returnTpt += ", " += rhs += ")"
71+
this += "DefDef(\"" += name += "\", " ++= typeParams += ", " +++= paramss += ", " += returnTpt += ", " += rhs += ")"
7272
case TypeDef(name, rhs) =>
73-
this += "TypeDef(" += name += ", " += rhs += ")"
73+
this += "TypeDef(\"" += name += "\", " += rhs += ")"
7474
case ClassDef(name, constr, parents, self, body) =>
75-
this += "ClassDef(" += name += ", " += constr += ", "
75+
this += "ClassDef(\"" += name += "\", " += constr += ", "
7676
visitList[Parent](parents, {
7777
case parent @ Term() => this += parent
7878
case parent @ TypeTree() => this += parent
7979
})
8080
this += ", " += self += ", " ++= body += ")"
8181
case PackageDef(name, members) =>
82-
this += "PackageDef(" += name += ", " ++= members += ")"
82+
this += "PackageDef(\"" += name += "\", " ++= members += ")"
8383
case Import(expr, selectors) =>
8484
this += "Import(" += expr += ", " ++= selectors += ")"
8585
case PackageClause(pid, stats) =>
@@ -90,9 +90,9 @@ class TastyPrinter[T <: Tasty with Singleton](val tasty: T) {
9090
case TypeTree.Synthetic() =>
9191
this += "Synthetic()"
9292
case TypeTree.TypeIdent(name) =>
93-
this += "TypeIdent(" += name += ")"
93+
this += "TypeIdent(\"" += name += "\")"
9494
case TypeTree.TypeSelect(qualifier, name) =>
95-
this += "TypeSelect(" += qualifier += ", " += name += ")"
95+
this += "TypeSelect(" += qualifier += ", \"" += name += "\")"
9696
case TypeTree.Singleton(ref) =>
9797
this += "Singleton(" += ref += ")"
9898
case TypeTree.And(left, right) =>
@@ -120,7 +120,7 @@ class TastyPrinter[T <: Tasty with Singleton](val tasty: T) {
120120
case Pattern.Value(v) =>
121121
this += "Value(" += v += ")"
122122
case Pattern.Bind(name, body) =>
123-
this += "Bind(" += name += ", " += body += ")"
123+
this += "Bind(\"" += name += "\", " += body += ")"
124124
case Pattern.Unapply(fun, implicits, patterns) =>
125125
this += "Unapply(" += fun += ", " ++= implicits += ", " ++= patterns += ")"
126126
case Pattern.Alternative(patterns) =>
@@ -140,28 +140,28 @@ class TastyPrinter[T <: Tasty with Singleton](val tasty: T) {
140140
case Constant.Long(value) => this += "Long(" += value += ")"
141141
case Constant.Float(value) => this += "Float(" += value += ")"
142142
case Constant.Double(value) => this += "Double(" += value += ")"
143-
case Constant.String(value) => this += "String(" += value += ")"
143+
case Constant.String(value) => this += "String(\"" += value += "\")"
144144
}
145145

146146
def visitType(x: TypeOrBounds): Buffer = x match {
147147
case Type.ConstantType(value) =>
148148
this += "ConstantType(" += value += ")"
149149
case Type.SymRef(sym, qual) =>
150150
def visitName(sym: Definition): Buffer = sym match {
151-
case ValDef(name, _, _) => this += "ValDef(" += name += ", _, _)"
152-
case DefDef(name, _, _, _, _) => this += "DefDef(" += name += ", _, _, _, _)"
153-
case TypeDef(name, _) => this += "TypeDef(" += name += ", _)"
154-
case ClassDef(name, _, _, _, _) => this += "ClassDef(" += name += ", _, _, _, _)"
155-
case PackageDef(name, _) => this += "PackageDef(" += name += ", _)"
151+
case ValDef(name, _, _) => this += "ValDef(\"" += name += "\", _, _)"
152+
case DefDef(name, _, _, _, _) => this += "DefDef(\"" += name += "\", _, _, _, _)"
153+
case TypeDef(name, _) => this += "TypeDef(\"" += name += "\", _)"
154+
case ClassDef(name, _, _, _, _) => this += "ClassDef(\"" += name += "\", _, _, _, _)"
155+
case PackageDef(name, _) => this += "PackageDef(\"" += name += "\", _)"
156156
case _ => this += "#"
157157
}
158158
this += "SymRef("
159159
visitName(sym)
160160
this += ", " += qual += ")"
161161
case Type.TermRef(name, qual) =>
162-
this += "TermRef(" += name += ", " += qual += ")"
162+
this += "TermRef(\"" += name += "\", " += qual += ")"
163163
case Type.TypeRef(name, qual) =>
164-
this += "TypeRef(" += name += ", " += qual += ")"
164+
this += "TypeRef(\"" += name += "\", " += qual += ")"
165165
case Type.Refinement(parent, name, info) =>
166166
this += "Refinement(" += parent += ", " += name += ", " += info += ")"
167167
case Type.AppliedType(tycon, args) =>
@@ -201,7 +201,7 @@ class TastyPrinter[T <: Tasty with Singleton](val tasty: T) {
201201

202202
def visitId(x: Id): Buffer = {
203203
val Id(name) = x
204-
this += "Id(" += name += ")"
204+
this += "Id(\"" += name += "\")"
205205
}
206206

207207
def visitSignature(sig: Signature): Buffer = {

0 commit comments

Comments
 (0)