[Issue 5373] Regression (2.051) CTFE and std.string.replace() causes "Bad binary function q{a == b}..

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 3 16:40:22 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5373


Rob Jacques <sandford at jhu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |patch
           Priority|P2                          |P3
          Component|DMD                         |Phobos
           Severity|normal                      |regression


--- Comment #7 from Rob Jacques <sandford at jhu.edu> 2011-02-03 16:38:01 PST ---
(In reply to comment #6)
> Well the other bug report was purely about phobos.
> The question is if this is just a workaround for an issue that actually needs
> to be addressed in dmd.

_Not_ a Phobos bug? *sigh* Here's the bug in all it's detail:

//Reduction 1
import std.string;
pragma(msg, replace(int.stringof,"int","real"));

//Reduction 2
pragma(msg, indexOf("int","real")  );

//Reduction 3
pragma(msg, is(typeof(startsWith!"a == b"("int","real")))  );

//Reduction 4
bool startsWith2(alias pred = "a == b", R, E)
(R doesThisStart, E withThis)
if (is(typeof(binaryFun!pred(doesThisStart.front, withThis))))
{
    return true;
}
pragma(msg, is(typeof(startsWith2!"a == b"("int","real")))  );

//Final Reduction
pragma(msg, is(typeof(binaryFun!"a == b"("int".front, "real"))) );

So what's happening here is that DMD is trying to execute replace at
compile-time. Replace calls indexOf, which calls startsWith. Now startsWith has
three overload sets which differ by their template constraints. So DMD
evaluates each constraint in turn. Which then causes in invalid binaryFun call,
which triggers a static assert. And static assert stops compilation then and
there. As this is per spec (AssignExpression is evaluated at compile time, and
converted to a boolean value. If the value is true, the static assert is
ignored. If the value is false, an error diagnostic is issued and the compile
fails. 
Unlike AssertExpressions, StaticAsserts are always checked and evaluted by the
compiler unless they appear in an unsatisfied conditional.) This isn't a
regression in DMD; it's a regression in Phobos due to better conformance of DMD
to the spec. Now, there does appear to be an inconsistency between static
assert's behavior during CTFE vs Non-CTFE, but that's more of an issue with the
Non-CTFE behavior vs the CTFE behavior.

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


More information about the Digitalmars-d-bugs mailing list