Skip to content

Commit 3eb419e

Browse files
committed
Give context for code examples
1 parent 039d582 commit 3eb419e

File tree

1 file changed

+100
-5
lines changed

1 file changed

+100
-5
lines changed

go/ql/lib/semmle/go/Decls.qll

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,28 @@ class TypeDefSpec extends @typedefspec, TypeSpec { }
423423
* Examples:
424424
*
425425
* ```go
426+
* Name string `json:"name"`
426427
* s string
427428
* x, y int
429+
* p *Point
428430
* Close() error
429431
* io.Reader
430432
* ~int | float32
431433
* ```
434+
* as in the following code:
435+
* ```go
436+
* struct {
437+
* io.Reader
438+
* Name string `json:"name"`
439+
* x, y int
440+
* }
441+
* func (p *Point) f(s string) (x, y int) { }
442+
* type MyInterface interface {
443+
* Close() error
444+
* io.Reader
445+
* ~int32 | float32
446+
* }
447+
* ```
432448
*/
433449
class FieldBase extends @field, ExprParent {
434450
/**
@@ -451,6 +467,15 @@ class FieldBase extends @field, ExprParent {
451467
* Name string `json:"name"`
452468
* x, y int
453469
* ```
470+
*
471+
* as in the following code:
472+
*
473+
* ```go
474+
* struct {
475+
* Name string `json:"name"`
476+
* x, y int
477+
* }
478+
* ```
454479
*/
455480
class FieldDecl extends FieldBase, Documentable, ExprParent {
456481
StructTypeExpr st;
@@ -488,6 +513,14 @@ class FieldDecl extends FieldBase, Documentable, ExprParent {
488513
* ```go
489514
* io.Reader
490515
* ```
516+
*
517+
* as in the following code:
518+
*
519+
* ```go
520+
* struct {
521+
* io.Reader
522+
* }
523+
* ```
491524
*/
492525
class EmbeddedFieldDecl extends FieldDecl {
493526
EmbeddedFieldDecl() { not exists(this.getNameExpr(_)) }
@@ -501,9 +534,16 @@ class EmbeddedFieldDecl extends FieldDecl {
501534
* Examples:
502535
*
503536
* ```go
504-
* name string
537+
* s string
505538
* x, y int
506539
* ```
540+
*
541+
* as in the following code:
542+
*
543+
* ```go
544+
* func f(s string, x, y int) { }
545+
* func g() (s string, x, y int){ return }
546+
* ```
507547
*/
508548
class ParameterOrResultDecl extends FieldBase, Documentable, ExprParent {
509549
int rawIndex;
@@ -542,9 +582,15 @@ class ParameterOrResultDecl extends FieldBase, Documentable, ExprParent {
542582
* Examples:
543583
*
544584
* ```go
545-
* name string
585+
* s string
546586
* x, y int
547587
* ```
588+
*
589+
* as in the following code:
590+
*
591+
* ```go
592+
* func f(s string, x, y int) { }
593+
* ```
548594
*/
549595
class ParameterDecl extends ParameterOrResultDecl {
550596
ParameterDecl() { rawIndex >= 0 }
@@ -569,6 +615,13 @@ class ParameterDecl extends ParameterOrResultDecl {
569615
* p *Point
570616
* r io.Reader
571617
* ```
618+
*
619+
* as in the following code:
620+
*
621+
* ```go
622+
* func (p *Point) f() { }
623+
* func (r io.Reader) g() { }
624+
* ```
572625
*/
573626
class ReceiverDecl extends FieldBase, Documentable, ExprParent {
574627
FuncDecl fd;
@@ -600,6 +653,14 @@ class ReceiverDecl extends FieldBase, Documentable, ExprParent {
600653
* r io.Reader
601654
* x, y int
602655
* ```
656+
*
657+
* as in the following code:
658+
*
659+
* ```go
660+
* func f(error) { return nil }
661+
* func g(r io.Reader) { return nil }
662+
* func h(x, y int) { return }
663+
* ```
603664
*/
604665
class ResultVariableDecl extends ParameterOrResultDecl {
605666
ResultVariableDecl() { rawIndex < 0 }
@@ -621,11 +682,18 @@ class ResultVariableDecl extends ParameterOrResultDecl {
621682
* Examples:
622683
*
623684
* ```go
624-
* T any
625685
* S, T comparable
686+
* U any
626687
* K ~int32 | float32
627688
* _ any
628689
* ```
690+
*
691+
* as in the following code:
692+
*
693+
* ```go
694+
* type GenericStruct[S, T comparable, U any, K ~int32 | float32, _ any] struct { }
695+
* func GenericFunction[S, T comparable, U any, K ~int32 | float32, _ any]() {}
696+
* ```
629697
*/
630698
class TypeParamDecl extends @typeparamdecl, Documentable, ExprParent {
631699
TypeParamDecl() { typeparamdecls(this, _, _) }
@@ -681,10 +749,20 @@ class TypeParamDecl extends @typeparamdecl, Documentable, ExprParent {
681749
* Examples:
682750
*
683751
* ```go
684-
* Read([]byte) (int, error)
752+
* Close() error
685753
* io.Reader
686754
* ~int32 | float32
687755
* ```
756+
*
757+
* as in the following code:
758+
*
759+
* ```go
760+
* type MyInterface interface {
761+
* Close() error
762+
* io.Reader
763+
* ~int32 | float32
764+
* }
765+
* ```
688766
*/
689767
class InterfaceMemberSpec extends FieldBase, Documentable, ExprParent {
690768
InterfaceTypeExpr ite;
@@ -710,7 +788,15 @@ class InterfaceMemberSpec extends FieldBase, Documentable, ExprParent {
710788
* Examples:
711789
*
712790
* ```go
713-
* Read([]byte) (int, error)
791+
* Close() error
792+
* ```
793+
*
794+
* as in the following code:
795+
*
796+
* ```go
797+
* type MyInterface interface {
798+
* Close() error
799+
* }
714800
* ```
715801
*/
716802
class MethodSpec extends InterfaceMemberSpec {
@@ -737,6 +823,15 @@ class MethodSpec extends InterfaceMemberSpec {
737823
* io.Reader
738824
* ~int32 | float32
739825
* ```
826+
*
827+
* as in the following code:
828+
*
829+
* ```go
830+
* type MyInterface interface {
831+
* io.Reader
832+
* ~int32 | float32
833+
* }
834+
* ```
740835
*/
741836
class EmbeddingSpec extends InterfaceMemberSpec {
742837
EmbeddingSpec() { not exists(this.getChildExpr(1)) }

0 commit comments

Comments
 (0)