Skip to content

Commit 9a629c3

Browse files
committed
Add Symbol.isPatternBound
1 parent e5a4b3e commit 9a629c3

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ object Symbols {
540540
d != null && d.flagsUNSAFE.is(Private)
541541
}
542542

543+
/** Is the symbol a pattern bound symbol?
544+
*/
545+
final def isPatternBound(implicit ctx: Context): Boolean =
546+
!isClass && this.is(Case, butNot = Enum | Module)
547+
543548
/** The symbol's signature if it is completed or a method, NotAMethod otherwise. */
544549
final def signature(implicit ctx: Context): Signature =
545550
if (lastDenot != null && (lastDenot.isCompleted || lastDenot.is(Method)))

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,13 @@ class TreeChecker extends Phase with SymTransformer {
174174

175175
/** The following invariant holds:
176176
*
177-
* patBoundSyms.contains(sym) <=> patternBound(sym)
177+
* patBoundSyms.contains(sym) <=> sym.isPatternBound
178178
*/
179-
def patternBound(sym: Symbol)(implicit ctx: Context): Boolean =
180-
(sym.isType && !sym.isClass && sym.isOneOf(Case)) ||
181-
(sym.isTerm && sym.isOneOf(Case, butNot = Enum | Module))
182-
183179
def withPatSyms[T](syms: List[Symbol])(op: => T)(implicit ctx: Context): T = {
184180
syms.foreach { sym =>
185181
assert(
186-
patternBound(sym),
187-
"patBoundSyms.contains(sym) => patternBound(sym) is broken." +
182+
sym.isPatternBound,
183+
"patBoundSyms.contains(sym) => sym.isPatternBound is broken." +
188184
i" Pattern bound symbol $sym has incorrect flags: " + sym.flagsString + ", line " + sym.sourcePos.line
189185
)
190186
}
@@ -214,8 +210,8 @@ class TreeChecker extends Phase with SymTransformer {
214210

215211
if (!ctx.phase.patternTranslated)
216212
assert(
217-
!patternBound(sym) || patBoundSyms.contains(sym),
218-
i"patternBound(sym) => patBoundSyms.contains(sym) is broken, sym = $sym, line " + tree.sourcePos.line
213+
!sym.isPatternBound || patBoundSyms.contains(sym),
214+
i"sym.isPatternBound => patBoundSyms.contains(sym) is broken, sym = $sym, line " + tree.sourcePos.line
219215
)
220216
}
221217

0 commit comments

Comments
 (0)