From 18b813b93ffdbacecde6a064549205114812a22d Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Fri, 3 Jan 2025 18:30:41 +0000 Subject: [PATCH] fix(check): line-break between diagnostic message chain entries (#27543) --- cli/tsc/diagnostics.rs | 2 +- .../check/message_chain_formatting/__test__.jsonc | 6 ++++++ .../message_chain_formatting.out | 10 ++++++++++ .../message_chain_formatting.ts | 8 ++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/specs/check/message_chain_formatting/__test__.jsonc create mode 100644 tests/specs/check/message_chain_formatting/message_chain_formatting.out create mode 100644 tests/specs/check/message_chain_formatting/message_chain_formatting.ts diff --git a/cli/tsc/diagnostics.rs b/cli/tsc/diagnostics.rs index 3f866e0c96..cda41525c2 100644 --- a/cli/tsc/diagnostics.rs +++ b/cli/tsc/diagnostics.rs @@ -90,9 +90,9 @@ impl DiagnosticMessageChain { s.push_str(&" ".repeat(level * 2)); s.push_str(&self.message_text); if let Some(next) = &self.next { - s.push('\n'); let arr = next.clone(); for dm in arr { + s.push('\n'); s.push_str(&dm.format_message(level + 1)); } } diff --git a/tests/specs/check/message_chain_formatting/__test__.jsonc b/tests/specs/check/message_chain_formatting/__test__.jsonc new file mode 100644 index 0000000000..1b5b49d8a9 --- /dev/null +++ b/tests/specs/check/message_chain_formatting/__test__.jsonc @@ -0,0 +1,6 @@ +// Regression test for https://github.com/denoland/deno/issues/27411. +{ + "args": "check --quiet message_chain_formatting.ts", + "output": "message_chain_formatting.out", + "exitCode": 1 +} diff --git a/tests/specs/check/message_chain_formatting/message_chain_formatting.out b/tests/specs/check/message_chain_formatting/message_chain_formatting.out new file mode 100644 index 0000000000..ca5c646ccb --- /dev/null +++ b/tests/specs/check/message_chain_formatting/message_chain_formatting.out @@ -0,0 +1,10 @@ +error: TS2769 [ERROR]: No overload matches this call. + Overload 1 of 3, '(s: string, b: boolean): void', gave the following error. + Argument of type 'number' is not assignable to parameter of type 'boolean'. + Overload 2 of 3, '(ss: string[], b: boolean): void', gave the following error. + Argument of type 'string' is not assignable to parameter of type 'string[]'. + Overload 3 of 3, '(ss: string[], b: Date): void', gave the following error. + Argument of type 'string' is not assignable to parameter of type 'string[]'. +foo("hello", 42); +~~~ + at [WILDLINE]/message_chain_formatting.ts:8:1 diff --git a/tests/specs/check/message_chain_formatting/message_chain_formatting.ts b/tests/specs/check/message_chain_formatting/message_chain_formatting.ts new file mode 100644 index 0000000000..ed342629ea --- /dev/null +++ b/tests/specs/check/message_chain_formatting/message_chain_formatting.ts @@ -0,0 +1,8 @@ +function foo(s: string, b: boolean): void; +function foo(ss: string[], b: boolean): void; +function foo(ss: string[], b: Date): void; +function foo(sOrSs: string | string[], b: boolean | Date): void { + console.log(sOrSs, b); +} + +foo("hello", 42);