@@ -731,17 +731,25 @@ func (pc *passContext) checkBasicBlock(fn *ssa.Function, block *ssa.BasicBlock,
731731 rv , rls = pc .checkInstruction (inst , lff , ls )
732732 if rls != nil {
733733 failed := false
734+
735+ // if there is no line information attached to the return
736+ // instruction, use the line info of the function itself
737+ pos := rv .Pos ()
738+ if (pos == token .NoPos ) {
739+ pos = rv .Parent ().Pos ()
740+ }
741+
734742 // Validate held locks.
735743 for fieldName , fg := range lff .HeldOnExit {
736744 r := fg .Resolver .resolveStatic (pc , ls , fn , rv )
737745 if ! r .valid () {
738746 // This cannot be forced, since we have no reference.
739- pc .maybeFail (rv . Pos () , "lock %s cannot be resolved" , fieldName )
747+ pc .maybeFail (pos , "lock %s cannot be resolved" , fieldName )
740748 continue
741749 }
742750 if s , ok := rls .isHeld (r , fg .Exclusive ); ! ok {
743751 if _ , ok := pc .forced [pc .positionKey (rv .Pos ())]; ! ok && ! lff .Ignore {
744- pc .maybeFail (rv . Pos () , "lock %s (%s) not held %s (locks: %s)" , fieldName , s , exclusiveStr (fg .Exclusive ), rls .String ())
752+ pc .maybeFail (pos , "lock %s (%s) not held %s (locks: %s)" , fieldName , s , exclusiveStr (fg .Exclusive ), rls .String ())
745753 failed = true
746754 } else {
747755 // Force the lock to be acquired.
@@ -751,7 +759,7 @@ func (pc *passContext) checkBasicBlock(fn *ssa.Function, block *ssa.BasicBlock,
751759 }
752760 // Check for other locks, but only if the above didn't trip.
753761 if ! failed && rls .count () != len (lff .HeldOnExit ) && ! lff .Ignore {
754- pc .maybeFail (rv . Pos () , "return with unexpected locks held (locks: %s)" , rls .String ())
762+ pc .maybeFail (pos , "return with unexpected locks held (locks: %s)" , rls .String ())
755763 }
756764 }
757765 }
0 commit comments