d: Fix error using UFCS in a speculative context

This reverts a change in the upstream D implementation of the compiler,
as it is no longer necessary since another fix for opDispatch got
applied in the same area (merged in r12-6003-gfd43568cc54e17).

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd ed17b3e95d.

Reviewed-on: https://github.com/dlang/dmd/pull/21132
This commit is contained in:
Iain Buclaw 2025-04-02 21:21:14 +02:00
parent 716d39f0a2
commit a66de265ab
5 changed files with 97 additions and 9 deletions

View file

@ -1,4 +1,4 @@
c6863be7206eef3c393726363a480baf0a0c6530
ed17b3e95dc3fc3264a4c91843da824f5541f3e1
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.

View file

@ -1247,6 +1247,9 @@ private Expression resolveUFCS(Scope* sc, CallExp ce)
}
else
{
if (arrayExpressionSemantic(ce.arguments.peekSlice(), sc))
return ErrorExp.get();
if (Expression ey = die.dotIdSemanticProp(sc, 1))
{
if (ey.op == EXP.error)
@ -1254,19 +1257,11 @@ private Expression resolveUFCS(Scope* sc, CallExp ce)
ce.e1 = ey;
if (isDotOpDispatch(ey))
{
// even opDispatch and UFCS must have valid arguments,
// so now that we've seen indication of a problem,
// check them for issues.
Expressions* originalArguments = Expression.arraySyntaxCopy(ce.arguments);
const errors = global.startGagging();
e = ce.expressionSemantic(sc);
if (!global.endGagging(errors))
return e;
if (arrayExpressionSemantic(originalArguments.peekSlice(), sc))
return ErrorExp.get();
/* fall down to UFCS */
}
else

View file

@ -0,0 +1,77 @@
struct Nullable(T)
{
static struct DontCallDestructorT
{
T payload;
}
DontCallDestructorT _value;
string toString() const
{
Appender!string app;
formatValueImpl(app, _value);
return null;
}
}
struct Appender(A)
{
InPlaceAppender!A impl;
}
struct InPlaceAppender(T)
{
static void toStringImpl(const T[] data)
{
string app;
formatValue(app, data);
}
}
void formatValueImpl(Writer, T)(Writer, const(T)) {}
void formatValueImpl(Writer, T)(Writer w, T obj)
if (is(T == U[], U))
{
formatValue(w, obj[0]);
}
enum HasToStringResult
{
none,
bla
}
template hasToString(T)
{
static if (is(typeof(
(T val) {
val.toString(s);
})))
enum hasToString = HasToStringResult.bla;
else
enum hasToString = HasToStringResult.none;
}
void formatValueImpl(Writer, T)(ref Writer w, T val)
if (is(T == struct) || is(T == union))
{
static if (hasToString!T)
int dummy;
formatElement(w, val.tupleof);
}
void formatElement(Writer, T)(Writer w, T val)
{
formatValueImpl(w, val);
}
void formatValue(Writer, T)(Writer w, T val)
{
formatValueImpl(w, val);
}

View file

@ -0,0 +1,12 @@
import imports.test21098_phobos : Appender, Nullable;
struct Type {
Nullable!(Type[]) templateArgs;
}
Type[] parseDeclarations() {
Appender!(Type[]) members;
return null;
}
enum ast = parseDeclarations();

View file

@ -0,0 +1,4 @@
// https://github.com/dlang/dmd/issues/21098
// EXTRA_FILES: imports/test21098b.d imports/test21098_phobos.d
import imports.test21098b;