Skip to content

Commit

Permalink
Merge pull request #8506 from RazvanN7/Improve_error
Browse files Browse the repository at this point in the history
Fix Issue 19098 - Improve error for non-assignable struct
merged-on-behalf-of: Jacob Carlborg <jacob-carlborg@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Sep 6, 2018
2 parents 88de313 + 2d13435 commit 7940798
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/dmd/expression.d
Expand Up @@ -959,7 +959,8 @@ extern (C++) abstract class Expression : RootObject
}
else if (!type.isAssignable())
{
error("cannot modify struct `%s` `%s` with `immutable` members", toChars(), type.toChars());
error("cannot modify struct instance `%s` of type `%s` because it contains `const` or `immutable` members",
toChars(), type.toChars());
return new ErrorExp();
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/fail_compilation/fail19098.d
@@ -0,0 +1,19 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail19098.d(18): Error: cannot modify struct instance `a` of type `A` because it contains `const` or `immutable` members
---
*/

struct A
{
const int a;
this(int) {}
}

void main()
{
A a = A(2);
A b = A(3);
a = b;
}

0 comments on commit 7940798

Please sign in to comment.