Skip to content

Commit b8f1ef8

Browse files
authored
diag(preview=in): Don't mention rvalue for in parameter with preview=in (dlang#21411)
Because the compiler can pass rvalues to ref parameters with preview=in, it is confusing and potentially misleading to have it mention rvalues.
1 parent 8dbb5a0 commit b8f1ef8

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

compiler/src/dmd/typesem.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ private const(char)* getParamError(TypeFunction tf, Expression arg, Parameter pa
11961196
auto at = qual ? arg.type.toPrettyChars(true) : arg.type.toChars();
11971197
OutBuffer buf;
11981198
// only mention rvalue if it's relevant
1199-
const rv = !arg.isLvalue() && par.isReference();
1199+
const rv = !arg.isLvalue() && par.isReference() && !(par.storageClass & STC.constscoperef);
12001200
buf.printf("cannot pass %sargument `%s` of type `%s` to parameter `%s`",
12011201
rv ? "rvalue ".ptr : "".ptr, arg.toErrMsg(), at,
12021202
parameterToChars(par, tf, qual));
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
REQUIRED_ARGS: -preview=in -preview=dip1000
3+
TEST_OUTPUT:
4+
----
5+
fail_compilation/previewin3.d(2): Error: function `foo` is not callable using argument types `(int)`
6+
fail_compilation/previewin3.d(2): cannot pass argument `42` of type `int` to parameter `in WithDtor`
7+
fail_compilation/previewin3.d(8): `previewin3.foo(in WithDtor)` declared here
8+
----
9+
*/
10+
11+
#line 1
12+
void rvalueErrorMsg () {
13+
foo(42);
14+
}
15+
16+
// Add a dtor to ensure things are passed by ref
17+
struct WithDtor { ~this() @safe pure nothrow @nogc {} }
18+
19+
void foo(in WithDtor) {}

0 commit comments

Comments
 (0)