18670, "mppf", "Should we allow implicit conversions from param string to bytes?", "2021-11-01T23:23:19Z"
I was looking at some function resolution code that allows implicit conversions from string literals / params to c_string
and wondered if we should allow implicit conversions from string
params to bytes
.
A related question is whether or not string
values should implicitly convert to bytes
. Note however that because these have the default intent of const ref
, we would not be able to create an implicit conversion when passing that way. That is because we don't want to create surprising copies in code that appears to only work with references - in particular it could create behavior changes if the const ref
refers to a global that is then modified, say. As a result, the implicit conversion would only apply for in
intent formals. However, this problem does not apply to param
strings / string literals.
Here is an example program that doesn't compile today, but could compile if we allow param strings to implicitly convert to bytes:
proc foo(arg: bytes) { }
foo("test");
One interesting property of this choice is that we could allow '
as a variable suffix (per #16310) if we were to remove both b'bla"
and c'bla'
string forms (which mean bytes literal and c-string literals today). I think we are expecting to completely deprecate c_string
at some point. And then, maybe we don't need bytes literals if we can have implicit conversions.