You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are cases where we add diagnostics with a source range from file A to the TypeCheckDiagnosticsBuilder of file B. A small example to trigger this bug is the following:
# test.pyfromsubprocessimportPopen
We currently emit a (false positive?) invalid-base diagnostic here, probably because we don't understand the definition of Popen:
But the actual problem here is that we attach the diagnostic to test.py, not to typeshed/stdlib/subprocess.pyi (notice the large column offset, resulting from trying to translate the byte offset into line/col on the wrong file):
error[invalid-base] /home/shark/playground/test.py:3:61460 Invalid class base with type `object` (all bases must be a class, `Any`, `Unknown` or `Todo`)
I noticed this, because things can go wrong bad if the byte offset from file A does not translate to a valid-UTF-8 offset in file B. Or if there are out-of-bounds accesses (which are for some reason also only triggered with non-ASCII characters):
# ÄfromsubprocessimportPopen
thread 'main' panicked at crates/ruff_source_file/src/line_index.rs:117:28:
byte index 61498 is out of bounds of `# ä
from subprocess import Popen
`
What needs to be done here?
Add an assertion to TypeCheckDiagnosticsBuilder that makes sure we never attach diagnostics for nodes from a different file?
Prevent raising diagnostics from different files in the first place?
The text was updated successfully, but these errors were encountered:
There are cases where we add diagnostics with a source range from file
A
to theTypeCheckDiagnosticsBuilder
of fileB
. A small example to trigger this bug is the following:We currently emit a (false positive?)
invalid-base
diagnostic here, probably because we don't understand the definition ofPopen
:ruff/crates/red_knot_vendored/vendor/typeshed/stdlib/subprocess.pyi
Line 1845 in 924741c
But the actual problem here is that we attach the diagnostic to
test.py
, not totypeshed/stdlib/subprocess.pyi
(notice the large column offset, resulting from trying to translate the byte offset into line/col on the wrong file):I noticed this, because things can go wrong bad if the byte offset from file A does not translate to a valid-UTF-8 offset in file B. Or if there are out-of-bounds accesses (which are for some reason also only triggered with non-ASCII characters):
What needs to be done here?
TypeCheckDiagnosticsBuilder
that makes sure we never attach diagnostics for nodes from a different file?The text was updated successfully, but these errors were encountered: