Exemple #1
0
        bool InstanceResolve(ParseContext ec, bool leftInstance, bool mustDoCs1540Check)
        {
            if (_isStatic)
            {
                InstanceExpression = null;
                return(true);
            }

            if (InstanceExpression == null)
            {
                // TODO: SimpleName.Error_ObjectRefRequired(ec, loc, GetSignatureForError());
                return(false);
            }

            InstanceExpression = InstanceExpression.DoResolve(ec);
            if (leftInstance && InstanceExpression != null)
            {
                InstanceExpression = InstanceExpression.ResolveLValue(ec, EmptyExpression.LValueMemberAccess);
            }

            if (InstanceExpression == null)
            {
                return(false);
            }

            if (mustDoCs1540Check && (InstanceExpression != EmptyExpression.Null) &&
                !TypeManager.IsInstantiationOfSameGenericType(InstanceExpression.Type, null) &&
                !TypeManager.IsNestedChildOf(null, InstanceExpression.Type))
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        private Expression DoResolve(ParseContext ec, bool leftValue, bool outAccess)
        {
            if (!_fieldInfo.IsStatic)
            {
                if (InstanceExpression == null)
                {
                    //
                    // This can happen when referencing an instance field using
                    // a fully qualified type expression: TypeName.InstanceField = xxx
                    //

                    // TODO: SimpleName.Error_ObjectRefRequired(ec, loc, GetSignatureForError());
                    return(null);
                }

                // Resolve the field's instance expression while flow analysis is turned
                // off: when accessing a field "a.b", we must check whether the field
                // "a.b" is initialized, not whether the whole struct "a" is initialized.

                if (leftValue)
                {
                    var rightSide = outAccess
                                        ? EmptyExpression.LValueMemberOutAccess
                                        : EmptyExpression.LValueMemberAccess;

                    if (InstanceExpression != EmptyExpression.Null)
                    {
                        InstanceExpression = InstanceExpression.ResolveLValue(ec, rightSide);
                    }
                }
                else
                {
                    const ResolveFlags rf = ResolveFlags.VariableOrValue | ResolveFlags.DisableFlowAnalysis;

                    if (InstanceExpression != EmptyExpression.Null)
                    {
                        InstanceExpression = InstanceExpression.Resolve(ec, rf);
                    }
                }

                if (InstanceExpression == null)
                {
                    return(null);
                }
            }

            // TODO: the code above uses some non-standard multi-resolve rules
            if (ExpressionClass != ExpressionClass.Invalid)
            {
                return(this);
            }

            ExpressionClass = ExpressionClass.Variable;

            // If the instance expression is a local variable or parameter.
            return(this);
        }