Skip to content

Commit 308815a

Browse files
authored
Fix crash with bad format string in parser error (#6133)
1 parent fd34024 commit 308815a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

parser/Parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void explainError(core::GlobalState &gs, core::FileRef file, core::ErrorBuilder
6363
if (lCurlyPos != string::npos && rCurlyPos != string::npos) {
6464
replacement[lCurlyPos] = '(';
6565
replacement[rCurlyPos] = ')';
66-
e.replaceWith("Replace the curly braces with parens", loc, replacement);
66+
e.replaceWith("Replace the curly braces with parens", loc, "{}", replacement);
6767
}
6868
}
6969
break;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# typed: true
2+
3+
class A
4+
def example
5+
example{&:"{}"}
6+
# ^^^^^^^^ error: block pass should not be enclosed in curly braces
7+
end
8+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -- test/testdata/parser/crash_block_pass_suggestion.rb --
2+
# typed: true
3+
4+
class A
5+
def example
6+
example(&:"{}")
7+
# ^^^^^^^^ error: block pass should not be enclosed in curly braces
8+
end
9+
end
10+
# ------------------------------

0 commit comments

Comments
 (0)