March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | > #!/usr/bin/env rdmd-dev-module
>
> unittest {
> import std.stdio: wln = writeln;
> import std.string;
> wln(typeof("a".z).stringof);
> }
Correction:
unittest {
import std.stdio: wln = writeln;
import std.string;
alias z = toStringz;
wln(typeof("a".z).stringof);
}
gives same error
t_string.d(7,19): Error: no property 'z' for type 'string'
|
March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | > Shouldn't be to hard to fix, though.
Does anybody know if there is an Issue for this?
|
March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Saturday, 22 March 2014 at 13:01:11 UTC, Nordlöw wrote:
> gives same error
That's because you made the alias local, UFCS only works with global symbols right now (which is actually by design, though I don't think it is a great design). So this works:
// move these out to module scope
import std.string;
alias z = toStringz;
unittest {
import std.stdio: wln = writeln;
wln(typeof("a".z).stringof); // now we're good/
}
|
March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Saturday, 22 March 2014 at 13:21:45 UTC, Adam D. Ruppe wrote:
> On Saturday, 22 March 2014 at 13:01:11 UTC, Nordlöw wrote:
>> gives same error
>
> That's because you made the alias local, UFCS only works with global symbols right now (which is actually by design, though I don't think it is a great design). So this works:
>
> // move these out to module scope
> import std.string;
> alias z = toStringz;
>
> unittest {
> import std.stdio: wln = writeln;
> wln(typeof("a".z).stringof); // now we're good/
> }
Ok. Great.
Still...I believe a warning hint should be outputted. This is not obvious.
/Per
|
March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On 3/22/14, "Nordlöw" <per.nordlow@gmail.com> wrote:
> DMD currently cannot infer aliases to be callable using UCFS unfortunately
Actually you're running into UFCS not working for module-scoped imports. The following will work:
-----
import std.stdio: wln = writeln;
import std.string;
alias toStringz z;
void main()
{
wln(typeof("a".z).stringof); // works ok
}
-----
UFCS not working for module-scoped imports is a filed bug.
|
March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | > UFCS not working for module-scoped imports is a filed bug.
Ok.
Great!
|
March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On 3/22/14, 6:01 AM, "Nordlöw" wrote:
>> #!/usr/bin/env rdmd-dev-module
>>
>> unittest {
>> import std.stdio: wln = writeln;
>> import std.string;
>> wln(typeof("a".z).stringof);
>> }
>
> Correction:
>
> unittest {
> import std.stdio: wln = writeln;
> import std.string;
> alias z = toStringz;
> wln(typeof("a".z).stringof);
> }
>
> gives same error
>
> t_string.d(7,19): Error: no property 'z' for type 'string'
Please bugzilla, thanks! -- Andrei
|
March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | > UFCS not working for module-scoped imports is a filed bug.
Do you a reference to this bugzilla issue?
|
March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | > That's because you made the alias local, UFCS only works with global symbols right now (which is actually by design, though I don't think it is a great design).
What were the motivations behind this choice of design?
|
March 22, 2014 Re: [Proposal] Add module for C-strings support in Phobos | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On 3/22/14, "Nordlöw" <per.nordlow@gmail.com> wrote: >> UFCS not working for module-scoped imports is a filed bug. > > Do you have a reference to this bugzilla issue? https://d.puremagic.com/issues/show_bug.cgi?id=6185 |
Copyright © 1999-2021 by the D Language Foundation