@@ -586,18 +586,29 @@ 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
+ func (v * visitor ) checkAssignment (lhs , rhs []ast.Expr ) (followed bool ) {
611
+ followed = true
601
612
if len (rhs ) == 1 {
602
613
// single value on rhs; check against lhs identifiers
603
614
if call , ok := rhs [0 ].(* ast.CallExpr ); ok {
@@ -619,11 +630,11 @@ func (v *visitor) checkAssignment(lhs, rhs []ast.Expr) {
619
630
}
620
631
} else if assert , ok := rhs [0 ].(* ast.TypeAssertExpr ); ok {
621
632
if ! v .asserts {
622
- return
633
+ return false
623
634
}
624
635
if assert .Type == nil {
625
636
// type switch
626
- return
637
+ return false
627
638
}
628
639
if len (lhs ) < 2 {
629
640
// assertion result not read
@@ -632,6 +643,7 @@ func (v *visitor) checkAssignment(lhs, rhs []ast.Expr) {
632
643
// assertion result ignored
633
644
v .addErrorAtPosition (id .NamePos , nil )
634
645
}
646
+ return false
635
647
}
636
648
} else {
637
649
// multiple value on rhs; in this case a call can't return
@@ -661,6 +673,21 @@ func (v *visitor) checkAssignment(lhs, rhs []ast.Expr) {
661
673
}
662
674
}
663
675
}
676
+
677
+ return
678
+ }
679
+
680
+ func (v * visitor ) checkAssertExpr (expr * ast.TypeAssertExpr ) bool {
681
+ if ! v .asserts {
682
+ return false
683
+ }
684
+ if expr .Type == nil {
685
+ // type switch
686
+ return false
687
+ }
688
+ v .addErrorAtPosition (expr .Pos (), nil )
689
+
690
+ return false
664
691
}
665
692
666
693
func isErrorType (t types.Type ) bool {
0 commit comments