[Issue 5134] std.algorithm.startsWith won't accept var from in as first arg

2011-07-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5134


yebblies yebbl...@gmail.com changed:

   What|Removed |Added

 CC||yebbl...@gmail.com
  Component|DMD |Phobos


--- Comment #1 from yebblies yebbl...@gmail.com 2011-07-12 22:17:02 EST ---
This is not a regression in dmd, but the result of fixing a dmd
accepts-invalid.
I'll leave it up to the phobos developers to decide if this is a regression or
not.  There are other similar bugs in bugzilla, and also enhancement requests
for dmd that may make this valid code again.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 5134] std.algorithm.startsWith won't accept var from in as first arg

2011-07-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5134


Jonathan M Davis jmdavisp...@gmx.com changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 CC||jmdavisp...@gmx.com
 Resolution||INVALID


--- Comment #2 from Jonathan M Davis jmdavisp...@gmx.com 2011-07-12 11:25:38 
PDT ---
Of course startsWith won't accept something which was an in parameter. That
would make it const. And a const range is useless. startsWith could work for
const arrays if templates were smart enough to realize that (see bug# 6148),
but they're not. They instantiate with the exact type that you give them, and a
const array can't have popFront called on it, so it's useless in a range-based
function.

Now, if the fix for bug# 6289 gets pulled in, then it'll be possible to use
const arrays with range-based functions by slicing them

void foo(in string str)
{
startsWith(str[], a);
}

but as long as a slice of an array is the exact same type as the original
instead of making the slice mutable (leaving the elements at the appropriate
level of mutability of coures - immutable in the case of string), that doesn't
work. You can cast the string - startsWith(cast(string)str, a) - and it
should work just fine, but as long str is const, it won't. So, this is not a
bug that's going to be fixed by changing anything with startsWith. It's an
inherent limitation in the language with regards to templates. Improving the
situation with slicing const/immutable arrays should help, because then you can
just slice them (as you would have to do with a static array), but until then,
a cast is your best option.

Of course, I would point out that having a string be in is of debatable value
in the first place, since the original array can't be altered anyway. All it
does is make it so that str can't be reassigned to another string inside of
foo. Granted, you may want that, but in plenty of cases, it really doesn't buy
you much.

So, this bug really isn't a bug. Fixing bug# 6289 would make slicing the string
work, which would effectively fix this issue, and if bug# 6148 were ever
implemented, then that would definitely fix it (though it's questionable
whether that's ever going to happen), but as it stands, startsWith isn't doing
anything wrong. If it worked before, it was a bug in dmd.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 5134] std.algorithm.startsWith won't accept var from in as first arg

2011-01-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5134


Andrei Alexandrescu and...@metalanguage.com changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 CC||and...@metalanguage.com
 AssignedTo|nob...@puremagic.com|and...@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---