Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/dmd/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -5197,19 +5197,6 @@ extern (C++) final class CastExp : UnaExp
return to ? new CastExp(loc, e1.syntaxCopy(), to.syntaxCopy()) : new CastExp(loc, e1.syntaxCopy(), mod);
}

override bool isLvalue()
{
//printf("e1.type = %s, to.type = %s\n", e1.type.toChars(), to.toChars());
return e1.isLvalue() && e1.type.mutableOf().unSharedOf().equals(to.mutableOf().unSharedOf());
}

override Expression toLvalue(Scope* sc, Expression e)
{
if (isLvalue())
return this;
return Expression.toLvalue(sc, e);
}

override Expression addDtorHook(Scope* sc)
{
if (to.toBasetype().ty == Tvoid) // look past the cast(void)
Expand Down
8 changes: 3 additions & 5 deletions src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -8748,17 +8748,15 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
// Try to do a decent error message with the expression
// before it got constant folded

// https://issues.dlang.org/show_bug.cgi?id=19754
// first see if the unoptimized expression is modifiable
if (e1x.op != TOK.variable)
e1x = e1x.optimize(WANTvalue);

if (exp.op == TOK.assign)
e1x = e1x.modifiableLvalue(sc, e1old);

if (checkIfIsStructLiteralDotExpr(e1x))
return setError();

if (e1x.op != TOK.variable)
e1x = e1x.optimize(WANTvalue);

if (e1x.op == TOK.error)
{
result = e1x;
Expand Down
8 changes: 1 addition & 7 deletions src/dmd/semantic3.d
Original file line number Diff line number Diff line change
Expand Up @@ -841,13 +841,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
const hasCopyCtor = exp.type.ty == Tstruct && (cast(TypeStruct)exp.type).sym.hasCopyCtor;
// if a copy constructor is present, the return type conversion will be handled by it
if (!hasCopyCtor)
{
if (f.isref && !MODimplicitConv(exp.type.mod, tret.mod) && !tret.isTypeSArray())
error(exp.loc, "expression `%s` of type `%s` is not implicitly convertible to return type `ref %s`",
exp.toChars(), exp.type.toChars(), tret.toChars());
else
exp = exp.implicitCastTo(sc2, tret);
}
exp = exp.implicitCastTo(sc2, tret);

if (f.isref)
{
Expand Down
7 changes: 0 additions & 7 deletions src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1377,13 +1377,6 @@ extern(C++) Type typeSemantic(Type t, Loc loc, Scope* sc)
e = new AddrExp(e.loc, e);
e = e.expressionSemantic(argsc);
}
if (isRefOrOut && (!isAuto || e.isLvalue())
&& !MODimplicitConv(e.type.mod, fparam.type.mod))
{
const(char)* errTxt = fparam.storageClass & STC.ref_ ? "ref" : "out";
.error(e.loc, "expression `%s` of type `%s` is not implicitly convertible to type `%s %s` of parameter `%s`",
e.toChars(), e.type.toChars(), errTxt, fparam.type.toChars(), fparam.toChars());
}
e = e.implicitCastTo(argsc, fparam.type);

// default arg must be an lvalue
Expand Down
11 changes: 0 additions & 11 deletions test/compilable/test19754.d

This file was deleted.

4 changes: 2 additions & 2 deletions test/fail_compilation/b20011.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/b20011.d(22): Error: cannot modify constant expression `S1(cast(ubyte)0u).member`
fail_compilation/b20011.d(25): Error: cannot modify constant expression `S2(null).member`
fail_compilation/b20011.d(22): Error: cannot modify constant `S1(cast(ubyte)0u).member`
fail_compilation/b20011.d(24): Error: `S2(null).member` is not an lvalue and cannot be modified
fail_compilation/b20011.d(26): Error: cannot modify constant expression `S2(null).member`
fail_compilation/b20011.d(27): Error: cannot modify constant expression `S2(null).member`
fail_compilation/b20011.d(30): Error: cannot modify constant expression `U1(cast(ubyte)0u, ).m2`
Expand Down
10 changes: 4 additions & 6 deletions test/fail_compilation/diag4596.d
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag4596.d(17): Error: `this` is not an lvalue and cannot be modified
fail_compilation/diag4596.d(18): Error: `this` is not an lvalue and cannot be modified
fail_compilation/diag4596.d(18): Error: `this` is not an lvalue and cannot be modified
fail_compilation/diag4596.d(20): Error: `super` is not an lvalue and cannot be modified
fail_compilation/diag4596.d(21): Error: `super` is not an lvalue and cannot be modified
fail_compilation/diag4596.d(21): Error: `super` is not an lvalue and cannot be modified
fail_compilation/diag4596.d(15): Error: `this` is not an lvalue and cannot be modified
fail_compilation/diag4596.d(16): Error: `1 ? this : this` is not an lvalue and cannot be modified
fail_compilation/diag4596.d(18): Error: `super` is not an lvalue and cannot be modified
fail_compilation/diag4596.d(19): Error: `1 ? super : super` is not an lvalue and cannot be modified
---
*/

Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail106.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail106.d(12): Error: cannot modify `immutable` expression `"ABC"[2]`
fail_compilation/fail106.d(12): Error: cannot modify `immutable` expression `'C'`
---
*/

Expand Down
14 changes: 8 additions & 6 deletions test/fail_compilation/fail17491.d
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* TEST_OUTPUT:
---
fail_compilation/fail17491.d(20): Error: `(S17491).init` is not an lvalue and cannot be modified
fail_compilation/fail17491.d(21): Error: `S17491(0)` is not an lvalue and cannot be modified
fail_compilation/fail17491.d(23): Error: cannot modify constant expression `S17491(0).field`
fail_compilation/fail17491.d(29): Error: `S17491(0)` is not an lvalue and cannot be modified
fail_compilation/fail17491.d(30): Error: `S17491(0)` is not an lvalue and cannot be modified
fail_compilation/fail17491.d(32): Error: cannot modify constant expression `S17491(0).field`
fail_compilation/fail17491.d(22): Error: `(S17491).init` is not an lvalue and cannot be modified
fail_compilation/fail17491.d(23): Error: `S17491(0)` is not an lvalue and cannot be modified
fail_compilation/fail17491.d(25): Error: cannot modify constant `S17491(0).field`
fail_compilation/fail17491.d(26): Error: cannot modify constant `*&S17491(0).field`
fail_compilation/fail17491.d(31): Error: `S17491(0)` is not an lvalue and cannot be modified
fail_compilation/fail17491.d(32): Error: `S17491(0)` is not an lvalue and cannot be modified
fail_compilation/fail17491.d(34): Error: cannot modify constant `S17491(0).field`
fail_compilation/fail17491.d(35): Error: cannot modify constant `*&S17491(0).field`
---
*/
// https://issues.dlang.org/show_bug.cgi?id=17491
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/fail351.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail351.d(14): Error: expression `this.num[index]` of type `immutable(uint)` is not implicitly convertible to return type `ref uint`
fail_compilation/fail351.d(14): Error: `cast(uint)this.num[index]` is not an lvalue and cannot be modified
---
*/

Expand Down
4 changes: 2 additions & 2 deletions test/fail_compilation/fail9891.d
Original file line number Diff line number Diff line change
@@ -1,8 +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(13): Error: `cast(int)i` is not an lvalue and cannot be modified
fail_compilation/fail9891.d(18): Error: `cast(int)i` is not an lvalue and cannot be modified
fail_compilation/fail9891.d(23): Error: `prop()` is not an lvalue and cannot be modified
---
*/
Expand Down
11 changes: 11 additions & 0 deletions test/compilable/test14929.d → test/fail_compilation/ice14929.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice14929.d(45): Error: `cast(Node)(*this.current).items[this.index]` is not an lvalue and cannot be modified
fail_compilation/ice14929.d(88): Error: template instance `ice14929.HashMap!(ulong, int).HashMap.opBinaryRight!"in"` error instantiating
fail_compilation/ice14929.d(92): instantiated from here: `HashmapComponentStorage!int`
fail_compilation/ice14929.d(92): Error: template instance `ice14929.isComponentStorage!(HashmapComponentStorage!int, int)` error instantiating
fail_compilation/ice14929.d(92): while evaluating: `static assert(isComponentStorage!(HashmapComponentStorage!int, int))`
---
*/

struct HashMap(K, V)
{
V* opBinaryRight(string op)(K key) const if (op == "in")
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/test12385.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/test12385.d(29): Error: cannot modify `immutable` expression `unbundled.x`
fail_compilation/test12385.d(29): Error: cannot modify `immutable` expression `BundledState("bla", 3).x`
---
*/

Expand Down