You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a previous LDM, we rejected defining a conversion from string to a custom handler type, saying that API authors should define one themselves if they so choose. However, this can cause some interesting issues with best common type that can require a language designer to explain why things work the way they do:
// No implicit conversion definedusingSystem;varx=((bool)(object)false)switch{true=>default(CustomHandler),false=>$"{1,2:f}Literal"};// Error: no best common typeConsole.WriteLine(x);
// Implicit conversion from CustomHandler to stringusingSystem;varx=((bool)(object)false)switch{true=>default(CustomHandler),false=>$"{1,2:f}Literal"};// x is stringConsole.WriteLine(x);publicpartialstructCustomHandler{publicstaticimplicitoperatorstring(CustomHandlerc)=>c.ToString();}
// Implicit conversion from string to CustomHandlerusingSystem;varx=((bool)(object)false)switch{true=>default(CustomHandler),false=>$"{1,2:f}Literal"};// x is CustomHandlerConsole.WriteLine(x);publicpartialstructCustomHandler{publicstaticimplicitoperatorCustomHandler(stringc)=> ...;}
This type of friction can arise in a number of places, such as lambda type inference, ternary best type inference, or null-coalescing best type inference.
While I don't think we should define a language-level conversion here, I think we should make a recommendation (as a language) that interpolated string handler types define a conversion from string to themselves in order to help users with these scenarios.
The text was updated successfully, but these errors were encountered:
In a previous LDM, we rejected defining a conversion from
string
to a custom handler type, saying that API authors should define one themselves if they so choose. However, this can cause some interesting issues with best common type that can require a language designer to explain why things work the way they do:This type of friction can arise in a number of places, such as lambda type inference, ternary best type inference, or null-coalescing best type inference.
While I don't think we should define a language-level conversion here, I think we should make a recommendation (as a language) that interpolated string handler types define a conversion from string to themselves in order to help users with these scenarios.
The text was updated successfully, but these errors were encountered: