From: "mame (Yusuke Endoh)" Date: 2022-09-27T08:10:50+00:00 Subject: [ruby-core:110103] [Ruby master Bug#19016] syntax_suggest is not working with Ruby 3.2.0-preview2 Issue #19016 has been updated by mame (Yusuke Endoh). There are two different sub-issues in this issue. ### 1. syntax_suggest does not work for `ruby foo.rb`. This is because a SyntaxError exception is not thrown even if there is a syntax error in foo.rb of `ruby foo.rb`. Instead, the interpreter prints the syntax error directly. So `Exception#detailed_message` is not called, which means syntax_suggest cannot intercept the exception handling. This could be fixed by throwing a SyntaxError exception even if there is a parse error in foo.rb, but I don't know how hard this fix will be implemented. ### 2. syntax_suggest does not work for `ruby -e 'load "foo.rb"'`. In this case, a SyntaxError exception is thrown, so `Exception#detailed_message` of syntax_suggest is actually called. However, `Exception#detailed_message` is called after the interpreter termination process has started. It is prohibited to create a new thread in this state, but syntax_suggest uses Timeout.timeout, which tries to create a new thread. This causes the failure `#` which @hsbt mentioned. [My PR](https://github.com/ruby/ruby/pull/6452) changes the order so that `Exception#detailed_message` is called *before* the interpreter termination process. However, I am a little afraid that this change has unforeseen side effects because it will print an error message when other threads are still running. @ko1 pointed that the following script prints `sub thread (RuntimeError)` and then `main thread (RuntimeError)` in Ruby 3.1, and that `main thread (RuntimeError)` and then `sub thread (RuntimeError)` with my PR applied. ```ruby Thread.new { begin sleep; ensure; raise "sub thread"; end } raise "main thread" ``` ``` $ ruby -v tt.rb ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux] # terminated with exception (report_on_exception is true): tt.rb:1:in `ensure in block in
': sub thread (RuntimeError) from tt.rb:1:in `block in
' tt.rb:2:in `
': main thread (RuntimeError) ``` ``` $ ./miniruby -v tt.rb ruby 3.2.0dev (2022-09-27T06:08:48Z error_print-before.. 4e8618306b) [x86_64-linux] tt.rb:2:in `
': main thread (RuntimeError) # terminated with exception (report_on_exception is true): tt.rb:1:in `ensure in block in
': sub thread (RuntimeError) from tt.rb:1:in `block in
' ``` ---------------------------------------- Bug #19016: syntax_suggest is not working with Ruby 3.2.0-preview2 https://bugs.ruby-lang.org/issues/19016#change-99361 * Author: hsbt (Hiroshi SHIBATA) * Status: Assigned * Priority: Normal * Assignee: hsbt (Hiroshi SHIBATA) * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- `syntax_suggest` is merged as default gems in Ruby 3.2.0-preview2. But it's not working yet. ``` $ cat bar.rb def foo def bar end $ ruby -v bar.rb ruby 3.2.0dev (2022-09-22T05:37:56Z master f07e651a90) +YJIT [arm64-darwin22] bar.rb:3: warning: mismatched indentations at 'end' with 'def' at 2 bar.rb:3: syntax error, unexpected end-of-input, expecting `end' ``` and gem version is also not working now. ``` $ cat foo.rb require "bundler/inline" gemfile do source "https://rubygems.org" gem "syntax_suggest" end require_relative "bar" ``` ``` $ ruby -v foo.rb ruby 3.2.0dev (2022-09-22T05:37:56Z master f07e651a90) +YJIT [arm64-darwin22] /path/to/bar.rb:3: warning: mismatched indentations at 'end' with 'def' at 2 foo.rb:8:in `require_relative': /path/to/bar.rb:3: syntax error, unexpected end-of-input, expecting `end' (SyntaxError) from foo.rb:8:in `
' ``` But Ruby 3.1 is works. ``` $ ruby -v foo.rb ruby 3.1.3p51 (2022-09-10 revision 9581248c4a) [arm64-darwin22] /path/to/bar.rb:3: warning: mismatched indentations at 'end' with 'def' at 2 --> /path/to/bar.rb Unmatched keyword, missing `end' ? 1 def foo ��� 2 def bar 3 end /Users/hsbt/.local/share/gem/gems/syntax_suggest-0.0.1/lib/syntax_suggest/core_ext.rb:93:in `require': /path/to/bar.rb:3: syntax error, unexpected end-of-input, expecting `end' (SyntaxError) from /Users/hsbt/.local/share/gem/gems/syntax_suggest-0.0.1/lib/syntax_suggest/core_ext.rb:93:in `require_relative' from foo.rb:8:in `
' ``` -- https://bugs.ruby-lang.org/ Unsubscribe: