public virtual void Error_ValueAssignment (ResolveContext rc, Expression rhs)
{
if (rhs == EmptyExpression.LValueMemberAccess || rhs == EmptyExpression.LValueMemberOutAccess) {
- rc.Report.SymbolRelatedToPreviousError (type);
- if (rc.CurrentInitializerVariable != null) {
- rc.Report.Error (1918, loc, "Members of value type `{0}' cannot be assigned using a property `{1}' object initializer",
- type.GetSignatureForError (), GetSignatureForError ());
- } else {
- rc.Report.Error (1612, loc, "Cannot modify a value type return value of `{0}'. Consider storing the value in a temporary variable",
- GetSignatureForError ());
- }
+ // Already reported as CS1612
} else {
rc.Report.Error (131, loc, "The left-hand side of an assignment must be a variable, a property or an indexer");
}
}
public bool ResolveInstanceExpression (ResolveContext rc, Expression rhs)
+ {
+ if (!ResolveInstanceExpressionCore (rc, rhs))
+ return false;
+
+ //
+ // Check intermediate value modification which won't have any effect
+ //
+ if (rhs != null && InstanceExpression.Type.IsStruct &&
+ (InstanceExpression is PropertyExpr || InstanceExpression is IndexerExpr || InstanceExpression is Invocation)) {
+
+ if (rc.CurrentInitializerVariable != null) {
+ rc.Report.Error (1918, loc, "Members of value type `{0}' cannot be assigned using a property `{1}' object initializer",
+ InstanceExpression.Type.GetSignatureForError (), InstanceExpression.GetSignatureForError ());
+ } else {
+ rc.Report.Error (1612, loc,
+ "Cannot modify a value type return value of `{0}'. Consider storing the value in a temporary variable",
+ InstanceExpression.GetSignatureForError ());
+ }
+ }
+
+ return true;
+ }
+
+ bool ResolveInstanceExpressionCore (ResolveContext rc, Expression rhs)
{
if (IsStatic) {
if (InstanceExpression != null) {
var me = InstanceExpression as MemberExpr;
if (me != null) {
- me.ResolveInstanceExpression (rc, rhs);
+ me.ResolveInstanceExpressionCore (rc, rhs);
// Using this check to detect probing instance expression resolve
if (!rc.OmitStructFlowAnalysis) {
return null;
}
- // if the property/indexer returns a value type, and we try to set a field in it
- if (right_side == EmptyExpression.LValueMemberAccess || right_side == EmptyExpression.LValueMemberOutAccess) {
- Error_ValueAssignment (ec, right_side);
- }
-
if (eclass == ExprClass.Unresolved) {
var expr = OverloadResolve (ec, right_side);
if (expr == null)