diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2025-04-02 21:21:14 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2025-04-02 22:01:57 +0200 |
commit | a66de265ab865aacbb6c4957916605c7bac7ff48 (patch) | |
tree | 29c8eca6c901c52343648a8ffaf68d24075c11b1 /gcc | |
parent | 716d39f0a248c1003033e6a312c736180790ef70 (diff) | |
download | gcc-a66de265ab865aacbb6c4957916605c7bac7ff48.zip gcc-a66de265ab865aacbb6c4957916605c7bac7ff48.tar.gz gcc-a66de265ab865aacbb6c4957916605c7bac7ff48.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/d/dmd/MERGE | 2 | ||||
-rw-r--r-- | gcc/d/dmd/expressionsem.d | 11 | ||||
-rw-r--r-- | gcc/testsuite/gdc.test/compilable/imports/test21098_phobos.d | 77 | ||||
-rw-r--r-- | gcc/testsuite/gdc.test/compilable/imports/test21098b.d | 12 | ||||
-rw-r--r-- | gcc/testsuite/gdc.test/compilable/test21098.d | 4 |
5 files changed, 97 insertions, 9 deletions
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index 00c8518..bd297b6 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -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. diff --git a/gcc/d/dmd/expressionsem.d b/gcc/d/dmd/expressionsem.d index 04efa1f..b0278cb 100644 --- a/gcc/d/dmd/expressionsem.d +++ b/gcc/d/dmd/expressionsem.d @@ -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 diff --git a/gcc/testsuite/gdc.test/compilable/imports/test21098_phobos.d b/gcc/testsuite/gdc.test/compilable/imports/test21098_phobos.d new file mode 100644 index 0000000..29c77eb --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/imports/test21098_phobos.d @@ -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); +} diff --git a/gcc/testsuite/gdc.test/compilable/imports/test21098b.d b/gcc/testsuite/gdc.test/compilable/imports/test21098b.d new file mode 100644 index 0000000..74c9fa8 --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/imports/test21098b.d @@ -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(); diff --git a/gcc/testsuite/gdc.test/compilable/test21098.d b/gcc/testsuite/gdc.test/compilable/test21098.d new file mode 100644 index 0000000..9b02b7b --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/test21098.d @@ -0,0 +1,4 @@ +// https://github.com/dlang/dmd/issues/21098 + +// EXTRA_FILES: imports/test21098b.d imports/test21098_phobos.d +import imports.test21098b; |