Skip to content

Commit 49db3d4

Browse files
committed
another one
1 parent 61f86fe commit 49db3d4

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

crates/artifacts/solc/src/error.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,21 @@ impl fmt::Display for Error {
147147
let mut lines = fmtd_msg.lines();
148148

149149
if let Some(l) = lines.clone().next() {
150-
// For whatever reason, exceptions are formatted differently in `message` and
151-
// `formattedMessage`:
152-
// YulException:Cannot swap...
153-
// vs:
154-
// YulException: Cannot swap...
155-
fn after_colon(s: &str) -> &str {
156-
s.find(':').map(|i| s[i + 1..].trim()).unwrap_or(s)
157-
}
158-
159-
let sl = short_msg.lines().next().unwrap_or("");
160-
if l.contains(sl) || after_colon(l).contains(after_colon(sl)) {
161-
// `fmtd_msg` contains `short_msg`.
162-
if l.bytes().filter(|b| *b == b':').count() >= 3 {
163-
// This is an old style error message, like:
164-
// path/to/file:line:column: ErrorType: message
165-
// We want to display this as-is.
166-
} else {
167-
// Otherwise, assume that the messages are the same until we find a source
168-
// location.
169-
lines.next();
170-
while lines.clone().next().is_some_and(|l| !l.contains("-->")) {
171-
lines.next();
150+
if l.bytes().filter(|&b| b == b':').count() >= 3
151+
&& (l.contains(['/', '\\']) || l.contains(".sol"))
152+
{
153+
// This is an old style error message, like:
154+
// path/to/file:line:column: ErrorType: message
155+
// We want to display this as-is.
156+
} else {
157+
// Otherwise, assume that the messages are the same until we find a source
158+
// location.
159+
lines.next();
160+
while let Some(line) = lines.clone().next() {
161+
if line.contains("-->") {
162+
break;
172163
}
164+
lines.next();
173165
}
174166
}
175167
}
@@ -448,4 +440,13 @@ mod tests {
448440
assert_eq!(s.match_indices("Cannot swap Variable _23").count(), 1, "\n{s}");
449441
assert!(s.contains("-->"), "\n{s}");
450442
}
443+
444+
#[test]
445+
fn stack_too_deep_no_source_location() {
446+
let error = r#"{"type":"CompilerError","component":"general","severity":"error","errorCode":null,"message":"Compiler error (/solidity/libyul/backends/evm/AsmCodeGen.cpp:63):Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables. When compiling inline assembly: Variable key_ is 2 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.","formattedMessage":"CompilerError: Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables. When compiling inline assembly: Variable key_ is 2 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.\n\n"}"#;
447+
let error = serde_json::from_str::<Error>(error).unwrap();
448+
let s = error.to_string();
449+
eprintln!("{s}");
450+
assert_eq!(s.match_indices("too deep inside the stack.").count(), 1, "\n{s}");
451+
}
451452
}

0 commit comments

Comments
 (0)