This is wrong though, because s refers to the RangeStmt itself, so s.End() is the closing brace. The consequence of this is if you try to use scope.LookupParent or types.Eval with a position inside the RangeStmt's block, it can't find the Key or Value variables.
I think the correct fix is to use s.X.End() instead.
Reviewing other check.declare calls, I think type switches are technically mishandled too. The spec says "the variable is declared at the beginning of the implicit block in each clause". I believe that should be the position of the "case" or "default" keywords, or at least at or immediately after the colon; not at the start of the first statement within the body.
These are preexisting issues, but fixing them should be very non-intrusive, so I'm hopeful it can still make 1.7.
@mdempsky I agree that this looks non-intrusive, but I believe @alandonovan has code that looks at scope ranges for various analyses. There may be subtle follow-up effects/errors that we don't foresee at the moment. I think it's better to leave for 1.8.
Go 1.8 included the fix for golang/go#15686, so no need to workaround
However, we also now have position information for imported objects,
which interferes with scoping rules. go/types doesn't export
Object.scopePos, so switch to using go/types.(*Scope).LookupParent