@@ -586,26 +586,38 @@ func (v *visitor) Visit(node ast.Node) ast.Visitor {
586
586
for _ , name := range vspec .Names {
587
587
lhs = append (lhs , ast .Expr (name ))
588
588
}
589
- v .checkAssignment (lhs , vspec .Values )
589
+ followed := v .checkAssignment (lhs , vspec .Values )
590
+ if ! followed {
591
+ return nil
592
+ }
590
593
}
591
594
592
595
case * ast.AssignStmt :
593
- v .checkAssignment (stmt .Lhs , stmt .Rhs )
596
+ followed := v .checkAssignment (stmt .Lhs , stmt .Rhs )
597
+ if ! followed {
598
+ return nil
599
+ }
600
+
601
+ case * ast.TypeAssertExpr :
602
+ v .checkAssertExpr (stmt )
603
+ return nil
594
604
595
605
default :
596
606
}
597
607
return v
598
608
}
599
609
600
- func (v * visitor ) checkAssignment (lhs , rhs []ast.Expr ) {
610
+ // checkAssignment checks the assignment statement and returns a boolean value
611
+ // indicating whether to continue checking the substructure in AssignStmt or not
612
+ func (v * visitor ) checkAssignment (lhs , rhs []ast.Expr ) (followed bool ) {
601
613
if len (rhs ) == 1 {
602
614
// single value on rhs; check against lhs identifiers
603
615
if call , ok := rhs [0 ].(* ast.CallExpr ); ok {
604
616
if ! v .blank {
605
- return
617
+ return true
606
618
}
607
619
if v .ignoreCall (call ) {
608
- return
620
+ return true
609
621
}
610
622
isError := v .errorsByArg (call )
611
623
for i := 0 ; i < len (lhs ); i ++ {
@@ -619,11 +631,11 @@ func (v *visitor) checkAssignment(lhs, rhs []ast.Expr) {
619
631
}
620
632
} else if assert , ok := rhs [0 ].(* ast.TypeAssertExpr ); ok {
621
633
if ! v .asserts {
622
- return
634
+ return false
623
635
}
624
636
if assert .Type == nil {
625
637
// type switch
626
- return
638
+ return false
627
639
}
628
640
if len (lhs ) < 2 {
629
641
// assertion result not read
@@ -632,6 +644,7 @@ func (v *visitor) checkAssignment(lhs, rhs []ast.Expr) {
632
644
// assertion result ignored
633
645
v .addErrorAtPosition (id .NamePos , nil )
634
646
}
647
+ return false
635
648
}
636
649
} else {
637
650
// multiple value on rhs; in this case a call can't return
@@ -661,6 +674,19 @@ func (v *visitor) checkAssignment(lhs, rhs []ast.Expr) {
661
674
}
662
675
}
663
676
}
677
+
678
+ return true
679
+ }
680
+
681
+ func (v * visitor ) checkAssertExpr (expr * ast.TypeAssertExpr ) {
682
+ if ! v .asserts {
683
+ return
684
+ }
685
+ if expr .Type == nil {
686
+ // type switch
687
+ return
688
+ }
689
+ v .addErrorAtPosition (expr .Pos (), nil )
664
690
}
665
691
666
692
func isErrorType (t types.Type ) bool {
0 commit comments