From 0283b5ddb4f3b90ceb1bde9cf76ae57d72ea80bb Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 10 Feb 2024 15:11:16 +0900 Subject: [PATCH] Check syntax warnings in built-in scripts --- tool/mk_builtin_loader.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb index 5afef655f4..c45b89c05d 100644 --- a/tool/mk_builtin_loader.rb +++ b/tool/mk_builtin_loader.rb @@ -8,6 +8,22 @@ SUBLIBS = {} REQUIRED = {} BUILTIN_ATTRS = %w[leaf inline_block use_block] +module CompileWarning + @@warnings = 0 + + def warn(message) + @@warnings += 1 + super + end + + def self.reset + w, @@warnings = @@warnings, 0 + w.nonzero? + end +end + +Warning.extend CompileWarning + def string_literal(lit, str = []) while lit case lit.first @@ -300,7 +316,15 @@ def mk_builtin_header file # bs = { func_name => argc } code = File.read(file) - collect_iseq RubyVM::InstructionSequence.compile(code).to_a + begin + verbose, $VERBOSE = $VERBOSE, true + collect_iseq RubyVM::InstructionSequence.compile(code, base).to_a + ensure + $VERBOSE = verbose + end + if warnings = CompileWarning.reset + raise "#{warnings} warnings in #{file}" + end collect_builtin(base, Ripper.sexp(code), 'top', bs = {}, inlines = {}) StringIO.open do |f|