{
this.is_embedded = true;
}
+
+ public override Expression CreateExpressionTree (EmitContext ec)
+ {
+ Report.Error (832, loc, "An expression tree cannot contain an assignment operator");
+ return null;
+ }
protected virtual Assign GetEmbeddedAssign (Location loc)
{
}
- if (target_type == source_type){
- if (source is New && target_type.IsValueType &&
- (target.eclass != ExprClass.IndexerAccess) && (target.eclass != ExprClass.PropertyAccess)){
- New n = (New) source;
+ if (target_type == source_type) {
+ if (target.eclass == ExprClass.Variable) {
+ New n = source as New;
+ if (n == null)
+ return this;
- if (n.SetValueTypeVariable (target))
+ if (n.HasInitializer) {
+ n.SetTargetVariable (target);
+ } else if (target_type.IsValueType) {
+ n.SetTargetVariable (target);
return n;
- else
- return null;
+ }
}
return this;
// This class implements fields and events class initializers
public class FieldInitializer : Assign
{
- public readonly DeclSpace TypeContainer;
+ //
+ // Keep resolved value because field initializers have their own rules
+ //
+ ExpressionStatement resolved;
- public FieldInitializer (FieldBuilder field, Expression expression, DeclSpace container)
+ public FieldInitializer (FieldBuilder field, Expression expression)
: base (new FieldExpr (field, expression.Location, true), expression)
{
- this.TypeContainer = container;
if (!field.IsStatic)
((FieldExpr)target).InstanceExpression = CompilerGeneratedThis.Instance;
}
+ public override Expression DoResolve (EmitContext ec)
+ {
+ // Field initializer can be resolved (fail) many times
+ if (Source == null)
+ return null;
+
+ if (resolved == null)
+ resolved = base.DoResolve (ec) as ExpressionStatement;
+
+ return resolved;
+ }
+
+ public override void EmitStatement (EmitContext ec)
+ {
+ if (resolved == null)
+ return;
+
+ if (resolved != this)
+ resolved.EmitStatement (ec);
+ else
+ base.EmitStatement (ec);
+ }
+
public bool IsComplexInitializer {
get {
if (embedded != null)
if (original_source == null)
return null;
- target = target.Resolve (ec);
+ using (ec.Set (EmitContext.Flags.InCompoundAssignment)) {
+ target = target.Resolve (ec);
+ }
+
if (target == null)
return null;
// into a tree, to guarantee that we do not have side
// effects.
//
- source = new Binary (op, target, original_source);
+ source = new Binary (op, target, original_source, true);
return base.DoResolve (ec);
}