michaeledgar / laser

Static analysis and style linter for Ruby code.
http://carboni.ca/projects/p/laser
GNU Affero General Public License v3.0
387 stars 17 forks source link

Simulate_require fails to require if extension is given #17

Open carl-ellis opened 12 years ago

carl-ellis commented 12 years ago

Using the test case:

a.rb:

class A
end 

b.rb:

require './a.rb'
class B
end

Then running: laser b.rb

I get the following stack trace: /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:369:insimulate_require': No such file: ./a.rb (LoadError) from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:284:in simulate_special_method' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:234:insimulate_call_dispatch' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:199:in simulate_call' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:190:insimulate_call_instruction' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:160:in simulate_instruction' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:112:insimulate_exit_instruction' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:96:in simulate_block' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:41:inblock in simulate' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:39:in loop' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/simulation.rb:39:insimulate' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow/control_flow_graph.rb:222:in analyze' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/control_flow.rb:23:inperform_cfg_analysis' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/annotations.rb:43:in block in perform_load_time_analysis' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/annotations.rb:38:ineach' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/annotations.rb:38:in perform_load_time_analysis' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/annotations.rb:15:inannotate_inputs' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/sexp_analysis.rb:10:in analyze_inputs' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/sexp_analysis.rb:21:inparse' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/analysis/sexp_analysis.rb:32:in find_sexps' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/warnings/rescue_exception.rb:11:inmatch?' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/warning.rb:93:in generated_warnings' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/scanner.rb:166:inblock in scan_for_warnings' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/scanner.rb:166:in map' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/scanner.rb:166:inscan_for_warnings' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/scanner.rb:138:in scan_for_file_warnings' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/scanner.rb:46:inscan' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/runner.rb:161:in block in collect_warnings' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/runner.rb:156:inmap' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/runner.rb:156:in collect_warnings' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/lib/laser/runner.rb:18:inrun' from /usr/lib/ruby/gems/1.9.1/gems/laser-0.7.0.pre2/bin/laser:7:in <top (required)>' from /usr/bin/laser:19:inload' from /usr/bin/laser:19:in <main>'

Whereas if I remove the ".rb" from the require line this works. I've tracked the problem down to /lib/laser/analysis/control_flow/simulation.rb:357 where you assume the trailing ".rb" is never present.