Thread overview
DMD 2.055
Sep 08, 2011
Joel Christensen
Sep 08, 2011
Joel Christensen
Sep 08, 2011
Johannes Pfau
Sep 08, 2011
Joel Christensen
Sep 08, 2011
bearophile
Sep 08, 2011
Daniel Murphy
Sep 08, 2011
Timon Gehr
Sep 08, 2011
Joel Christensen
September 08, 2011
I've got this program that does alters strings, but with D 2.055, it comes up with this error:

Here is the code, I copied it from my program:
http://p.baf.cc/3937
September 08, 2011
On 08-Sep-11 8:46 PM, Joel Christensen wrote:
> I've got this program that does alters strings, but with D 2.055, it
> comes up with this error:
>
> Here is the code, I copied it from my program:
> http://p.baf.cc/3937

Oops, accidently sent it prematurely.

Here is the error:
\jpro\dpro2\verseprompt\section.d(249): Error: incompatible types for ((__dgliteral1) ? (__dgliteral2)): 'string delegate(string text) pure' and 'string delegate(string text) @system'

- Joelcnz
September 08, 2011
Joel Christensen wrote:
>On 08-Sep-11 8:46 PM, Joel Christensen wrote:
> > I've got this program that does alters strings, but with D 2.055, it comes up with this error:
> >
> > Here is the code, I copied it from my program: http://p.baf.cc/3937
>
>Oops, accidently sent it prematurely.
>
>Here is the error:
>\jpro\dpro2\verseprompt\section.d(249): Error: incompatible types for
>((__dgliteral1) ? (__dgliteral2)): 'string delegate(string text) pure'
>and 'string delegate(string text) @system'
>
>- Joelcnz

It's a problem caused by purity and safety inference for delegate literals.

I assume the problem is in line 22 of the code you posted? As a workaround, try to explicitly cast the delegates to the same type:

[cast(string delegate(string))(string text) { return toLower(text); },
cast(string delegate(string))(string text) { return wipeOutChars(text,subchars); },
cast(string delegate(string))(string text) { return removeSpaces(text); } ]

-- 
Johannes Pfau

September 08, 2011
Also I can't compile programs like this any more:
\D\dmd2\windows\bin\dmd file1 file2 etc.

I've been using Geany (a light IDE), now I have to use the terminal to compile my programs (also clicking on a batch file), before I could compile with the hit of a key.

Actually I fix my problem in my previous post. Looks like this:
string doToLower( string str ) {
	return toLower( str );
}

- Joelcnz

September 08, 2011
On 08-Sep-11 9:05 PM, Johannes Pfau wrote:
> cast(string delegate(string))

Thanks Johannes, that's better than my way. :-)

- Joelcnz
September 08, 2011
Johannes Pfau:

> I assume the problem is in line 22 of the code you posted? As a workaround, try to explicitly cast the delegates to the same type:
> 
> [cast(string delegate(string))(string text) { return toLower(text); },
> cast(string delegate(string))(string text) { return wipeOutChars(text,subchars); },
> cast(string delegate(string))(string text) { return removeSpaces(text); } ]

Casts are dangerous. I think you are stripping away a @system.

This is reduced code that shows the OP problem:

int foo(int s) pure @safe {
    return 0;
}
int bar(int s) @system {
    return 1;
}
void main() {
    auto A = [(int x){ return foo(x); },
              (int x){ return bar(x); }];
    auto B = [cast(int delegate(int) @system)(int x){ return foo(x); },
              cast(int delegate(int) @system)(int x){ return bar(x); }];
}


With DMD 2.055:
test.d(9): Error: incompatible types for ((__dgliteral1) ? (__dgliteral2)): 'int delegate(int x) pure' and 'int delegate(int x) @system'

In my opinion the compiler has to use the most general type for A, avoiding the casts used in B. Do you know if this in Bugzilla already, and its entry number?

Bye,
bearophile
September 08, 2011
This is http://d.puremagic.com/issues/show_bug.cgi?id=6352 and more generally http://d.puremagic.com/issues/show_bug.cgi?id=3180 .  There is patch for 3180 that will hopefully be in the next release.

"Joel Christensen" <joelcnz@gmail.com> wrote in message news:j49vki$2phd$1@digitalmars.com...
> On 08-Sep-11 8:46 PM, Joel Christensen wrote:
> > I've got this program that does alters strings, but with D 2.055, it comes up with this error:
> >
> > Here is the code, I copied it from my program: http://p.baf.cc/3937
>
> Oops, accidently sent it prematurely.
>
> Here is the error:
> \jpro\dpro2\verseprompt\section.d(249): Error: incompatible types for
> ((__dgliteral1) ? (__dgliteral2)): 'string delegate(string text) pure' and
> 'string delegate(string text) @system'
>
> - Joelcnz


September 08, 2011
On 09/08/2011 03:42 PM, Daniel Murphy wrote:
> This is http://d.puremagic.com/issues/show_bug.cgi?id=6352 and more
> generally http://d.puremagic.com/issues/show_bug.cgi?id=3180 .  There is
> patch for 3180 that will hopefully be in the next release.
>
> "Joel Christensen"<joelcnz@gmail.com>  wrote in message
> news:j49vki$2phd$1@digitalmars.com...
>> On 08-Sep-11 8:46 PM, Joel Christensen wrote:
>>> I've got this program that does alters strings, but with D 2.055, it
>>> comes up with this error:
>>>
>>> Here is the code, I copied it from my program:
>>> http://p.baf.cc/3937
>>
>> Oops, accidently sent it prematurely.
>>
>> Here is the error:
>> \jpro\dpro2\verseprompt\section.d(249): Error: incompatible types for
>> ((__dgliteral1) ? (__dgliteral2)): 'string delegate(string text) pure' and
>> 'string delegate(string text) @system'
>>
>> - Joelcnz
>
>

Also note that that error message is really bad. CondExp could use a incompatibleTypes() override, like eg. this one:

void CondExp::incompatibleTypes()
{
    if (e1->type->toBasetype() != Type::terror &&
        e2->type->toBasetype() != Type::terror
       )
        error("incompatible types for (%s ? %s : %s): '%s' and '%s'",
             econd->toChars(), e1->toChars(), Token::toChars(op), e2->toChars(),
             e1->type->toChars(), e2->type->toChars());
}