Commit 493e2978

493e29785175Merged

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

Description

fix(parse): warn when require / require_relative cannot be resolved

Before this commit, require "foobar" was silently replaced with a comment when foobar.rb wasn't found under <exe_dir>/lib/. The compiled binary then ran as if the require had never been written. For users porting CRuby code, that hid real load failures — the program looked like it ran fine under spinel, but any call into the missing library compiled to 0 further down, often producing output that happened to look plausible.

The placeholder-comment substitution is kept (the program still links / runs, matching the existing "best-effort" stance), but both the require and require_relative paths now emit a one-line warning to stderr naming the unresolved library and the directory that was searched. Resolved-and-inlined requires stay silent.

Closes #596

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

Details

Commit
493e29785175
Parent
87a2ce25d6b7

spinel_parse.cmodifiedView file

@@ -1350,6 +1350,9 @@
13501350 sp_mark_path_included(canonical);
13511351 content = read_file(full_path);
13521352 if (!content) {
1353+ fprintf(stderr,
1354+ "warning: require_relative \"%s\" from %s could not be resolved (no such file: %s); the call is ignored\n",
1355+ rel_path, source_path, full_path);
13531356 content = strdup("# require_relative not found");
13541357 } else {
13551358 /* Recursively resolve */
@@ -1436,6 +1439,9 @@
14361439 free(canonical);
14371440 content = read_file(lib_path);
14381441 if (!content) {
1442+ fprintf(stderr,
1443+ "warning: require \"%s\" could not be resolved (no %s.rb in %s); the call is ignored\n",
1444+ lib_name, lib_name, lib_dir);
14391445 content = strdup("# require not resolved");
14401446 } else {
14411447 char *resolved = resolve_requires(content, lib_path);