Commit 799dd970

799dd9702a22Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Mark the entry file as included before resolving requires

A circular require_relative (a requires b, b requires a) where one of them is the compiled entry file re-spliced the entry's body a second time: the entry path was never registered in the included-paths set, so a back-reference to it was treated as a fresh include. That duplicated module-level ivar storage / top-level statements. Canonicalize the entry source path and sp_mark_path_included() it before resolve_requires, so a back-reference resolves to the dedup stub. Full suite green (846).

Refs #1373.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
799dd9702a22
Parent
690c5939a642

src/spinel_parse.cmodifiedView file

@@ -2259,6 +2259,14 @@
22592259 }
22602260
22612261 /* Resolve require_relative and plain require */
2262+ /* Register the entry file itself as already-included, so a circular
2263+ require_relative pointing back at it resolves to the dedup stub
2264+ instead of splicing the entry's body a second time (#1373). */
2265+ {
2266+ char *entry_canon = sp_canonical_path(source_file);
2267+ sp_mark_path_included(entry_canon);
2268+ free(entry_canon);
2269+ }
22622270 char *resolved = resolve_requires(source, source_file);
22632271 free(source);
22642272 source = resolve_plain_requires(resolved, argv0);