Skip to content

Commit 76a0a51

Browse files
authored
Merge pull request #715 from owen-mc/print-empty-interface-with-single-space
Pretty-print empty interface without double space
2 parents 314bd20 + 880afea commit 76a0a51

File tree

3 files changed

+63
-60
lines changed

3 files changed

+63
-60
lines changed

ql/lib/semmle/go/Types.qll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,16 @@ class InterfaceType extends @interfacetype, CompositeType {
541541

542542
language[monotonicAggregates]
543543
override string pp() {
544-
result =
545-
"interface { " +
544+
exists(string meth |
545+
meth =
546546
concat(string name, Type tp |
547547
tp = this.getMethodType(name)
548548
|
549-
name + " " + tp.pp(), "; " order by name
550-
) + " }"
549+
" " + name + " " + tp.pp(), ";" order by name
550+
)
551+
|
552+
result = "interface {" + meth + " }"
553+
)
551554
}
552555

553556
override string toString() { result = "interface type" }

ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ input.go:
5353
# 20| 0: [CallExpr] call to Println
5454
# 20| Type = (int, error)
5555
# 20| 0: [FunctionName, SelectorExpr] selection of Println
56-
# 20| Type = func([]interface { }) int, error
56+
# 20| Type = func([]interface { }) int, error
5757
# 20| 0: [Ident, PackageName] fmt
5858
# 20| 1: [FunctionName, Ident] Println
59-
# 20| Type = func([]interface { }) int, error
59+
# 20| Type = func([]interface { }) int, error
6060
# 20| 1: [StringLit] "Hi"
6161
# 20| Type = string
6262
# 20| Value = [StringLit] Hi
@@ -203,10 +203,10 @@ input.go:
203203
# 52| 0: [CallExpr] call to Println
204204
# 52| Type = (int, error)
205205
# 52| 0: [FunctionName, SelectorExpr] selection of Println
206-
# 52| Type = func([]interface { }) int, error
206+
# 52| Type = func([]interface { }) int, error
207207
# 52| 0: [Ident, PackageName] fmt
208208
# 52| 1: [FunctionName, Ident] Println
209-
# 52| Type = func([]interface { }) int, error
209+
# 52| Type = func([]interface { }) int, error
210210
# 52| 1: [StringLit] "Heard from ch1"
211211
# 52| Type = string
212212
# 52| Value = [StringLit] Heard from ch1
@@ -229,31 +229,31 @@ input.go:
229229
# 54| 0: [CallExpr] call to Println
230230
# 54| Type = (int, error)
231231
# 54| 0: [FunctionName, SelectorExpr] selection of Println
232-
# 54| Type = func([]interface { }) int, error
232+
# 54| Type = func([]interface { }) int, error
233233
# 54| 0: [Ident, PackageName] fmt
234234
# 54| 1: [FunctionName, Ident] Println
235-
# 54| Type = func([]interface { }) int, error
235+
# 54| Type = func([]interface { }) int, error
236236
# 54| 1: [Ident, VariableName] a
237237
# 54| Type = [1]float32
238238
# 55| 2: [ExprStmt] expression statement
239239
# 55| 0: [CallExpr] call to Println
240240
# 55| Type = (int, error)
241241
# 55| 0: [FunctionName, SelectorExpr] selection of Println
242-
# 55| Type = func([]interface { }) int, error
242+
# 55| Type = func([]interface { }) int, error
243243
# 55| 0: [Ident, PackageName] fmt
244244
# 55| 1: [FunctionName, Ident] Println
245-
# 55| Type = func([]interface { }) int, error
245+
# 55| Type = func([]interface { }) int, error
246246
# 55| 1: [Ident, VariableName] w
247247
# 55| Type = bool
248248
# 56| 2: [CommClause] comm clause
249249
# 57| 0: [ExprStmt] expression statement
250250
# 57| 0: [CallExpr] call to Println
251251
# 57| Type = (int, error)
252252
# 57| 0: [FunctionName, SelectorExpr] selection of Println
253-
# 57| Type = func([]interface { }) int, error
253+
# 57| Type = func([]interface { }) int, error
254254
# 57| 0: [Ident, PackageName] fmt
255255
# 57| 1: [FunctionName, Ident] Println
256-
# 57| Type = func([]interface { }) int, error
256+
# 57| Type = func([]interface { }) int, error
257257
# 58| 3: [CommClause] comm clause
258258
# 58| 0: [SendStmt] send statement
259259
# 58| 0: [Ident, VariableName] ch1
@@ -297,10 +297,10 @@ input.go:
297297
# 67| 0: [CallExpr] call to Println
298298
# 67| Type = (int, error)
299299
# 67| 0: [FunctionName, SelectorExpr] selection of Println
300-
# 67| Type = func([]interface { }) int, error
300+
# 67| Type = func([]interface { }) int, error
301301
# 67| 0: [Ident, PackageName] fmt
302302
# 67| 1: [FunctionName, Ident] Println
303-
# 67| Type = func([]interface { }) int, error
303+
# 67| Type = func([]interface { }) int, error
304304
# 67| 1: [Ident, VariableName] x
305305
# 67| Type = int
306306
# 68| 2: [BlockStmt] block statement
@@ -316,10 +316,10 @@ input.go:
316316
# 69| 0: [CallExpr] call to Println
317317
# 69| Type = (int, error)
318318
# 69| 0: [FunctionName, SelectorExpr] selection of Println
319-
# 69| Type = func([]interface { }) int, error
319+
# 69| Type = func([]interface { }) int, error
320320
# 69| 0: [Ident, PackageName] fmt
321321
# 69| 1: [FunctionName, Ident] Println
322-
# 69| Type = func([]interface { }) int, error
322+
# 69| Type = func([]interface { }) int, error
323323
# 69| 1: [MinusExpr] -...
324324
# 69| Type = int
325325
# 69| 0: [Ident, VariableName] x
@@ -450,20 +450,20 @@ input.go:
450450
# 107| Value = [ConstantName, Ident] true
451451
# 112| 16: [FuncDecl] function declaration
452452
# 112| 0: [FunctionName, Ident] test9
453-
# 112| Type = func(interface { })
453+
# 112| Type = func(interface { })
454454
# 112| 1: [FuncTypeExpr] function type
455455
# 112| 0: [ParameterDecl] parameter declaration
456456
# 112| 0: [InterfaceTypeExpr] interface type
457-
# 112| Type = interface { }
457+
# 112| Type = interface { }
458458
# 112| 1: [Ident, VariableName] x
459-
# 112| Type = interface { }
459+
# 112| Type = interface { }
460460
# 112| 2: [BlockStmt] block statement
461461
# 113| 0: [TypeSwitchStmt] type-switch statement
462462
# 113| 0: [DefineStmt] ... := ...
463463
# 113| 0: [Ident] y
464464
# 113| 1: [TypeAssertExpr] type assertion
465465
# 113| 0: [Ident, VariableName] x
466-
# 113| Type = interface { }
466+
# 113| Type = interface { }
467467
# 113| 1: [BlockStmt] block statement
468468
# 114| 0: [CaseClause] case clause
469469
# 114| 0: [Ident, TypeName] string
@@ -474,12 +474,12 @@ input.go:
474474
# 115| 0: [CallExpr] call to Println
475475
# 115| Type = (int, error)
476476
# 115| 0: [FunctionName, SelectorExpr] selection of Println
477-
# 115| Type = func([]interface { }) int, error
477+
# 115| Type = func([]interface { }) int, error
478478
# 115| 0: [Ident, PackageName] fmt
479479
# 115| 1: [FunctionName, Ident] Println
480-
# 115| Type = func([]interface { }) int, error
480+
# 115| Type = func([]interface { }) int, error
481481
# 115| 1: [Ident, VariableName] y
482-
# 115| Type = interface { }
482+
# 115| Type = interface { }
483483
# 116| 1: [CaseClause] case clause
484484
# 116| 0: [Ident, TypeName] float32
485485
# 116| Type = float32
@@ -502,13 +502,13 @@ input.go:
502502
# 121| 1: [TypeSwitchStmt] type-switch statement
503503
# 121| 0: [DefineStmt] ... := ...
504504
# 121| 0: [Ident, VariableName] y
505-
# 121| Type = interface { }
505+
# 121| Type = interface { }
506506
# 121| 1: [Ident, VariableName] x
507-
# 121| Type = interface { }
507+
# 121| Type = interface { }
508508
# 121| 1: [ExprStmt] expression statement
509509
# 121| 0: [TypeAssertExpr] type assertion
510510
# 121| 0: [Ident, VariableName] y
511-
# 121| Type = interface { }
511+
# 121| Type = interface { }
512512
# 121| 2: [BlockStmt] block statement
513513
# 122| 0: [CaseClause] case clause
514514
# 123| 0: [ExprStmt] expression statement
@@ -566,10 +566,10 @@ input.go:
566566
# 138| 0: [CallExpr] call to Print
567567
# 138| Type = (int, error)
568568
# 138| 0: [FunctionName, SelectorExpr] selection of Print
569-
# 138| Type = func([]interface { }) int, error
569+
# 138| Type = func([]interface { }) int, error
570570
# 138| 0: [Ident, PackageName] fmt
571571
# 138| 1: [FunctionName, Ident] Print
572-
# 138| Type = func([]interface { }) int, error
572+
# 138| Type = func([]interface { }) int, error
573573
# 138| 1: [Ident, VariableName] x
574574
# 138| Type = int
575575
# 141| 1: [RangeStmt] range statement
@@ -584,10 +584,10 @@ input.go:
584584
# 142| 0: [CallExpr] call to Print
585585
# 142| Type = (int, error)
586586
# 142| 0: [FunctionName, SelectorExpr] selection of Print
587-
# 142| Type = func([]interface { }) int, error
587+
# 142| Type = func([]interface { }) int, error
588588
# 142| 0: [Ident, PackageName] fmt
589589
# 142| 1: [FunctionName, Ident] Print
590-
# 142| Type = func([]interface { }) int, error
590+
# 142| Type = func([]interface { }) int, error
591591
# 142| 1: [Ident, VariableName] i
592592
# 142| Type = int
593593
# 142| 2: [Ident, VariableName] v

ql/test/library-tests/semmle/go/PrintAst/PrintAstExcludeComments.expected

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ input.go:
3333
# 20| 0: [CallExpr] call to Println
3434
# 20| Type = (int, error)
3535
# 20| 0: [FunctionName, SelectorExpr] selection of Println
36-
# 20| Type = func([]interface { }) int, error
36+
# 20| Type = func([]interface { }) int, error
3737
# 20| 0: [Ident, PackageName] fmt
3838
# 20| 1: [FunctionName, Ident] Println
39-
# 20| Type = func([]interface { }) int, error
39+
# 20| Type = func([]interface { }) int, error
4040
# 20| 1: [StringLit] "Hi"
4141
# 20| Type = string
4242
# 20| Value = [StringLit] Hi
@@ -183,10 +183,10 @@ input.go:
183183
# 52| 0: [CallExpr] call to Println
184184
# 52| Type = (int, error)
185185
# 52| 0: [FunctionName, SelectorExpr] selection of Println
186-
# 52| Type = func([]interface { }) int, error
186+
# 52| Type = func([]interface { }) int, error
187187
# 52| 0: [Ident, PackageName] fmt
188188
# 52| 1: [FunctionName, Ident] Println
189-
# 52| Type = func([]interface { }) int, error
189+
# 52| Type = func([]interface { }) int, error
190190
# 52| 1: [StringLit] "Heard from ch1"
191191
# 52| Type = string
192192
# 52| Value = [StringLit] Heard from ch1
@@ -209,31 +209,31 @@ input.go:
209209
# 54| 0: [CallExpr] call to Println
210210
# 54| Type = (int, error)
211211
# 54| 0: [FunctionName, SelectorExpr] selection of Println
212-
# 54| Type = func([]interface { }) int, error
212+
# 54| Type = func([]interface { }) int, error
213213
# 54| 0: [Ident, PackageName] fmt
214214
# 54| 1: [FunctionName, Ident] Println
215-
# 54| Type = func([]interface { }) int, error
215+
# 54| Type = func([]interface { }) int, error
216216
# 54| 1: [Ident, VariableName] a
217217
# 54| Type = [1]float32
218218
# 55| 2: [ExprStmt] expression statement
219219
# 55| 0: [CallExpr] call to Println
220220
# 55| Type = (int, error)
221221
# 55| 0: [FunctionName, SelectorExpr] selection of Println
222-
# 55| Type = func([]interface { }) int, error
222+
# 55| Type = func([]interface { }) int, error
223223
# 55| 0: [Ident, PackageName] fmt
224224
# 55| 1: [FunctionName, Ident] Println
225-
# 55| Type = func([]interface { }) int, error
225+
# 55| Type = func([]interface { }) int, error
226226
# 55| 1: [Ident, VariableName] w
227227
# 55| Type = bool
228228
# 56| 2: [CommClause] comm clause
229229
# 57| 0: [ExprStmt] expression statement
230230
# 57| 0: [CallExpr] call to Println
231231
# 57| Type = (int, error)
232232
# 57| 0: [FunctionName, SelectorExpr] selection of Println
233-
# 57| Type = func([]interface { }) int, error
233+
# 57| Type = func([]interface { }) int, error
234234
# 57| 0: [Ident, PackageName] fmt
235235
# 57| 1: [FunctionName, Ident] Println
236-
# 57| Type = func([]interface { }) int, error
236+
# 57| Type = func([]interface { }) int, error
237237
# 58| 3: [CommClause] comm clause
238238
# 58| 0: [SendStmt] send statement
239239
# 58| 0: [Ident, VariableName] ch1
@@ -277,10 +277,10 @@ input.go:
277277
# 67| 0: [CallExpr] call to Println
278278
# 67| Type = (int, error)
279279
# 67| 0: [FunctionName, SelectorExpr] selection of Println
280-
# 67| Type = func([]interface { }) int, error
280+
# 67| Type = func([]interface { }) int, error
281281
# 67| 0: [Ident, PackageName] fmt
282282
# 67| 1: [FunctionName, Ident] Println
283-
# 67| Type = func([]interface { }) int, error
283+
# 67| Type = func([]interface { }) int, error
284284
# 67| 1: [Ident, VariableName] x
285285
# 67| Type = int
286286
# 68| 2: [BlockStmt] block statement
@@ -296,10 +296,10 @@ input.go:
296296
# 69| 0: [CallExpr] call to Println
297297
# 69| Type = (int, error)
298298
# 69| 0: [FunctionName, SelectorExpr] selection of Println
299-
# 69| Type = func([]interface { }) int, error
299+
# 69| Type = func([]interface { }) int, error
300300
# 69| 0: [Ident, PackageName] fmt
301301
# 69| 1: [FunctionName, Ident] Println
302-
# 69| Type = func([]interface { }) int, error
302+
# 69| Type = func([]interface { }) int, error
303303
# 69| 1: [MinusExpr] -...
304304
# 69| Type = int
305305
# 69| 0: [Ident, VariableName] x
@@ -430,20 +430,20 @@ input.go:
430430
# 107| Value = [ConstantName, Ident] true
431431
# 112| 6: [FuncDecl] function declaration
432432
# 112| 0: [FunctionName, Ident] test9
433-
# 112| Type = func(interface { })
433+
# 112| Type = func(interface { })
434434
# 112| 1: [FuncTypeExpr] function type
435435
# 112| 0: [ParameterDecl] parameter declaration
436436
# 112| 0: [InterfaceTypeExpr] interface type
437-
# 112| Type = interface { }
437+
# 112| Type = interface { }
438438
# 112| 1: [Ident, VariableName] x
439-
# 112| Type = interface { }
439+
# 112| Type = interface { }
440440
# 112| 2: [BlockStmt] block statement
441441
# 113| 0: [TypeSwitchStmt] type-switch statement
442442
# 113| 0: [DefineStmt] ... := ...
443443
# 113| 0: [Ident] y
444444
# 113| 1: [TypeAssertExpr] type assertion
445445
# 113| 0: [Ident, VariableName] x
446-
# 113| Type = interface { }
446+
# 113| Type = interface { }
447447
# 113| 1: [BlockStmt] block statement
448448
# 114| 0: [CaseClause] case clause
449449
# 114| 0: [Ident, TypeName] string
@@ -454,12 +454,12 @@ input.go:
454454
# 115| 0: [CallExpr] call to Println
455455
# 115| Type = (int, error)
456456
# 115| 0: [FunctionName, SelectorExpr] selection of Println
457-
# 115| Type = func([]interface { }) int, error
457+
# 115| Type = func([]interface { }) int, error
458458
# 115| 0: [Ident, PackageName] fmt
459459
# 115| 1: [FunctionName, Ident] Println
460-
# 115| Type = func([]interface { }) int, error
460+
# 115| Type = func([]interface { }) int, error
461461
# 115| 1: [Ident, VariableName] y
462-
# 115| Type = interface { }
462+
# 115| Type = interface { }
463463
# 116| 1: [CaseClause] case clause
464464
# 116| 0: [Ident, TypeName] float32
465465
# 116| Type = float32
@@ -482,13 +482,13 @@ input.go:
482482
# 121| 1: [TypeSwitchStmt] type-switch statement
483483
# 121| 0: [DefineStmt] ... := ...
484484
# 121| 0: [Ident, VariableName] y
485-
# 121| Type = interface { }
485+
# 121| Type = interface { }
486486
# 121| 1: [Ident, VariableName] x
487-
# 121| Type = interface { }
487+
# 121| Type = interface { }
488488
# 121| 1: [ExprStmt] expression statement
489489
# 121| 0: [TypeAssertExpr] type assertion
490490
# 121| 0: [Ident, VariableName] y
491-
# 121| Type = interface { }
491+
# 121| Type = interface { }
492492
# 121| 2: [BlockStmt] block statement
493493
# 122| 0: [CaseClause] case clause
494494
# 123| 0: [ExprStmt] expression statement
@@ -546,10 +546,10 @@ input.go:
546546
# 138| 0: [CallExpr] call to Print
547547
# 138| Type = (int, error)
548548
# 138| 0: [FunctionName, SelectorExpr] selection of Print
549-
# 138| Type = func([]interface { }) int, error
549+
# 138| Type = func([]interface { }) int, error
550550
# 138| 0: [Ident, PackageName] fmt
551551
# 138| 1: [FunctionName, Ident] Print
552-
# 138| Type = func([]interface { }) int, error
552+
# 138| Type = func([]interface { }) int, error
553553
# 138| 1: [Ident, VariableName] x
554554
# 138| Type = int
555555
# 141| 1: [RangeStmt] range statement
@@ -564,10 +564,10 @@ input.go:
564564
# 142| 0: [CallExpr] call to Print
565565
# 142| Type = (int, error)
566566
# 142| 0: [FunctionName, SelectorExpr] selection of Print
567-
# 142| Type = func([]interface { }) int, error
567+
# 142| Type = func([]interface { }) int, error
568568
# 142| 0: [Ident, PackageName] fmt
569569
# 142| 1: [FunctionName, Ident] Print
570-
# 142| Type = func([]interface { }) int, error
570+
# 142| Type = func([]interface { }) int, error
571571
# 142| 1: [Ident, VariableName] i
572572
# 142| Type = int
573573
# 142| 2: [Ident, VariableName] v

0 commit comments

Comments
 (0)