Reject a script path that collides with the type stubs file

Merged
RA
2mo ago
+56-2

Fixes #717

If script_name is repl_type_stubs.pyi, the script gets written over the stubs file and ends up importing itself. #756 stopped the panic, but the type check result is still wrong: names from the stubs are reported as undefined, plus a "Cannot redefine T".

Now TypeChecker::run returns an error when the script and the stubs resolve to the same file. I compare files and not strings, so ./repl_type_stubs.pyi and similar paths are caught too.

The host sees it as "type checker failed". If you'd rather have it fail at Configure, I can move the check there.

Added a test in monty-type-checking and a subprocess test with the repro from the issue, both fail on main. fmt, clippy and the rust tests pass, I didn't run the python tests.


Summary by cubic

Rejects scripts whose path resolves to the same file as the type stubs, which previously caused the script to overwrite the stubs and import itself, making stub names undefined and spans underflow.

  • Compares interned files rather than strings, so paths like ./repl_type_stubs.pyi and sub/../repl_type_stubs.pyi are also caught.
  • The type checker now returns an error to the host; the RPC feed ends in an error instead of a crash.
  • Adds a unit test covering path-normalized collisions and a subprocess test with the repro from #717.