From da8b9752d51a8047ac4cf75e2be81f408ed7a9e9 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Wed, 27 Oct 2021 15:19:11 -0700 Subject: [PATCH] Fix overload resolution break --- proposals/utf8-string-literals.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/proposals/utf8-string-literals.md b/proposals/utf8-string-literals.md index 16c6ef5892..a46b0908b8 100644 --- a/proposals/utf8-string-literals.md +++ b/proposals/utf8-string-literals.md @@ -145,15 +145,16 @@ The second example is hard to make work because it requires conversions in both ### Overload resolution breaks -The following API would become ambiguous: +The following API would change meaning if we did not have a suffix: ```c# M(""); -static void M1(char[] charArray) => ...; +static void M1(ReadOnlySpan charSpan) => ...; static void M1(byte[] charArray) => ...; ``` -What should we do to address this? +Today this calls the `ReadOnlySpan` overload, because there is an implicit user-defined conversion from `string`. If we introduced a conversion-from-expression for all string +literals, then overload resolution would instead prefer the `byte[]` overload. ## Examples today Examples of where runtime has manually encoded the UTF8 bytes today