Fix pretty-printing of anonymous vars and multiple patterns; add test

This commit is contained in:
Chris Smowton
2024-03-22 20:51:10 +00:00
parent f317f782ae
commit 5cb5ee026c
4 changed files with 26 additions and 7 deletions

View File

@@ -400,7 +400,8 @@ private class PpInstanceOfExpr extends PpAst, InstanceOfExpr {
private class PpLocalVariableDeclExpr extends PpAst, LocalVariableDeclExpr {
override string getPart(int i) {
i = 0 and result = this.getName()
i = 0 and
(if this.isAnonymous() then result = "_" else result = this.getName())
or
i = 1 and result = " = " and exists(this.getInit())
}
@@ -793,7 +794,11 @@ private class PpPatternCase extends PpAst, PatternCase {
or
i = base + 2 and
this.getPatternAtIndex(n) instanceof LocalVariableDeclExpr and
not this.isAnonymousPattern(n) and
(
exists(this.getPatternAtIndex(n).asBindingOrUnnamedPattern().getTypeAccess())
or
not this.isAnonymousPattern(n)
) and
result = " "
or
i = base + 3 and
@@ -815,9 +820,10 @@ private class PpPatternCase extends PpAst, PatternCase {
override PpAst getChild(int i) {
exists(int n, int base | exists(this.getPatternAtIndex(n)) and base = n * 4 |
i = 1 and result = this.getPatternAtIndex(n).asBindingOrUnnamedPattern().getTypeAccess()
i = base + 1 and
result = this.getPatternAtIndex(n).asBindingOrUnnamedPattern().getTypeAccess()
or
i = 1 and result = this.getPatternAtIndex(n).asRecordPattern()
i = base + 1 and result = this.getPatternAtIndex(n).asRecordPattern()
)
or
exists(int base | base = (max(int n | exists(this.getPatternAtIndex(n))) + 1) * 4 |