From c3ccb5e0d01a3b96ba0256fc20e72abb25702f61 Mon Sep 17 00:00:00 2001 From: Manu Evans Date: Sat, 16 Nov 2024 23:56:32 +1000 Subject: [PATCH] Fixed more test fails... --- compiler/src/dmd/expressionsem.d | 3 ++- compiler/src/dmd/typesem.d | 4 ++-- compiler/test/compilable/reverthelp.d | 1 + compiler/test/fail_compilation/fail7603a.d | 7 ------- compiler/test/fail_compilation/fail7603b.d | 2 +- compiler/test/fail_compilation/fail7603c.d | 8 -------- compiler/test/fail_compilation/fail9773.d | 10 ---------- compiler/test/fail_compilation/fail9891.d | 10 ++-------- 8 files changed, 8 insertions(+), 37 deletions(-) delete mode 100644 compiler/test/fail_compilation/fail7603a.d delete mode 100644 compiler/test/fail_compilation/fail7603c.d delete mode 100644 compiler/test/fail_compilation/fail9773.d diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 6e2aeb46eda6..67cda8f76396 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -3288,6 +3288,7 @@ private bool functionParameters(const ref Loc loc, Scope* sc, else if (p.storageClass & STC.ref_) { if (global.params.rvalueRefParam == FeatureState.enabled && + !(p.storageClass & STC.return_) && !arg.isLvalue() && targ.isCopyable()) { /* allow rvalues to be passed to ref parameters by copying @@ -3298,7 +3299,7 @@ private bool functionParameters(const ref Loc loc, Scope* sc, ev = new CommaExp(arg.loc, ev, new VarExp(arg.loc, v)); arg = ev.expressionSemantic(sc); } - arg = arg.toLvalue(sc, "create `ref` parameter from"); + arg = arg.toLvalue(sc, (p.storageClass & STC.return_) ? "create `return ref` parameter from" : "create `ref` parameter from"); // Look for mutable misaligned pointer, etc., in @safe mode err |= checkUnsafeAccess(sc, arg, false, true); diff --git a/compiler/src/dmd/typesem.d b/compiler/src/dmd/typesem.d index eebbf45573dc..e308e557f50d 100644 --- a/compiler/src/dmd/typesem.d +++ b/compiler/src/dmd/typesem.d @@ -2287,8 +2287,8 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) // default arg must be an lvalue if (isRefOrOut && !isAuto && !(fparam.storageClass & STC.constscoperef) && - global.params.rvalueRefParam != FeatureState.enabled) - e = e.toLvalue(sc, "create default argument for `ref` / `out` parameter from"); + (global.params.rvalueRefParam != FeatureState.enabled || (fparam.storageClass & (STC.out_ | STC.return_)))) + e = e.toLvalue(sc, (global.params.rvalueRefParam == FeatureState.enabled) ? "create default argument for `return ref` / `out` parameter from" : "create default argument for `ref` / `out` parameter from"); fparam.defaultArg = e; return (e.op != EXP.error); diff --git a/compiler/test/compilable/reverthelp.d b/compiler/test/compilable/reverthelp.d index febbba1445a4..c8dab44e1bbb 100644 --- a/compiler/test/compilable/reverthelp.d +++ b/compiler/test/compilable/reverthelp.d @@ -9,5 +9,6 @@ Revertable language changes listed by -revert=name: =dip1000 revert DIP1000 changes (Scoped Pointers) (https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md) =intpromote revert integral promotions for unary + - ~ operators =dtorfields don't destruct fields of partially constructed objects + =rvaluerefparam revert rvalue arguments to ref parameters ---- */ diff --git a/compiler/test/fail_compilation/fail7603a.d b/compiler/test/fail_compilation/fail7603a.d deleted file mode 100644 index a106a566a5c4..000000000000 --- a/compiler/test/fail_compilation/fail7603a.d +++ /dev/null @@ -1,7 +0,0 @@ -/* -TEST_OUTPUT: ---- -fail_compilation/fail7603a.d(7): Error: cannot create default argument for `ref` / `out` parameter from constant `true` ---- -*/ -void test(ref bool val = true) { } diff --git a/compiler/test/fail_compilation/fail7603b.d b/compiler/test/fail_compilation/fail7603b.d index a6524221afd8..b261d29fc278 100644 --- a/compiler/test/fail_compilation/fail7603b.d +++ b/compiler/test/fail_compilation/fail7603b.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/fail7603b.d(7): Error: cannot create default argument for `ref` / `out` parameter from constant `true` +fail_compilation/fail7603b.d(7): Error: cannot create default argument for `return ref` / `out` parameter from constant `true` --- */ void test(out bool val = true) { } diff --git a/compiler/test/fail_compilation/fail7603c.d b/compiler/test/fail_compilation/fail7603c.d deleted file mode 100644 index 3d030fc9668c..000000000000 --- a/compiler/test/fail_compilation/fail7603c.d +++ /dev/null @@ -1,8 +0,0 @@ -/* -TEST_OUTPUT: ---- -fail_compilation/fail7603c.d(8): Error: cannot create default argument for `ref` / `out` parameter from constant `3` ---- -*/ -enum x = 3; -void test(ref int val = x) { } diff --git a/compiler/test/fail_compilation/fail9773.d b/compiler/test/fail_compilation/fail9773.d deleted file mode 100644 index 26447a73914e..000000000000 --- a/compiler/test/fail_compilation/fail9773.d +++ /dev/null @@ -1,10 +0,0 @@ -/* -TEST_OUTPUT: ---- -fail_compilation/fail9773.d(7): Error: cannot create default argument for `ref` / `out` parameter from expression `""` because it is not an lvalue ---- -*/ -void f(ref string a = "") -{ - a = "crash and burn"; -} diff --git a/compiler/test/fail_compilation/fail9891.d b/compiler/test/fail_compilation/fail9891.d index 0c2384fccfa4..b3a1e1625646 100644 --- a/compiler/test/fail_compilation/fail9891.d +++ b/compiler/test/fail_compilation/fail9891.d @@ -1,9 +1,8 @@ /* TEST_OUTPUT: --- -fail_compilation/fail9891.d(13): Error: expression `i` of type `immutable(int)` is not implicitly convertible to type `ref int` of parameter `n` -fail_compilation/fail9891.d(18): Error: expression `i` of type `immutable(int)` is not implicitly convertible to type `out int` of parameter `n` -fail_compilation/fail9891.d(23): Error: cannot create default argument for `ref` / `out` parameter from expression `prop()` because it is not an lvalue +fail_compilation/fail9891.d(12): Error: expression `i` of type `immutable(int)` is not implicitly convertible to type `ref int` of parameter `n` +fail_compilation/fail9891.d(17): Error: expression `i` of type `immutable(int)` is not implicitly convertible to type `out int` of parameter `n` --- */ @@ -19,8 +18,3 @@ void f2(out int n = i) { ++n; } - -void f3(ref int n = prop) -{ - ++n; -}