Allow implicit string literal -> const(wchar_t)[]#8950
Allow implicit string literal -> const(wchar_t)[]#8950thewilsonator merged 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @thewilsonator! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#8950" |
|
cc @rainers is this going to do what I think it does? |
|
Tests? |
|
Could you provide some context ? I'm not sure I follow the reasoning. |
Also where are implicit conversions tested in the test suite? |
jacob-carlborg
left a comment
There was a problem hiding this comment.
- Needs to have tests
- Needs to have a changelog entry
- Needs to have a spec update
|
b2a5710 to
f2bfb1c
Compare
|
How is the implicit conversion from e.g. |
Geod24
left a comment
There was a problem hiding this comment.
It's not that simple. Check the following snippet:
import core.stdc.stdio;
import core.stdc.string;
import core.stdc.errno;
import std.conv;
import std.stdio;
extern(C) int wprintf(const __c_wchar_t* format, ...);
enum __c_wchar_t : dchar; // Use `wchar` if you are on Windows
static immutable string foo = "Hello World !\n";
void main ()
{
immutable(__c_wchar_t)[] str = foo;
if (-1 == wprintf(str.ptr))
writeln("Error: ", strerror(errno).to!string);
}This prints `Error: Illegal byte sequence" on my machine (OSX).
It's because this implicit conv is just blindly doing an array cast in this case. Removing one of the character will yield an "array cast misalignment" assert error.
There is no implicit conversion between {w,d}string and string, it's just that "foo" is not typed as string (but ""c is).
Side note: testing with literals is never enough.
|
Ahh, right. Where is the string literal specific stuff handled? Not |
f2bfb1c to
49518e2
Compare
Added tests for non-literal conversion failure
1880231 to
819e11c
Compare
|
I see no one approving this, why was it merged? |
| */ | ||
| if (TypeBasic tob = tn.toBasetype().isTypeBasic()) | ||
| result = tn.implicitConvTo(tob); | ||
| return; |
There was a problem hiding this comment.
Indentation here looks off. I can't tell whether the early return here should be part of the first or second condition.
|
Change brought by #9460 would break the test added in the PR. Have a look if you have some time to @thewilsonator . |
for druntime#2349