Exemple #1
0
        public override Expression DoResolve(ResolveContext rc)
        {
            eclass = ExprClass.Variable;
            IType tpexpr = (expr as ITypeReference).Resolve(rc);

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

            if (rc.IsStaticType(tpexpr))
            {
                rc.Report.Error(-244, loc, "The `default value' operator cannot be applied to an operand of a static type");
            }


            if (tpexpr is PointerTypeSpec)
            {
                return(new NullConstant(tpexpr, Location));
            }

            if (tpexpr.IsReferenceType.HasValue && tpexpr.IsReferenceType.Value)
            {
                return(new NullConstant(tpexpr, loc));
            }

            // TODO:Add cast to nullable/struct
            return(Constant.CreateConstantFromValue(rc, tpexpr, ResolveContext.GetDefaultValue(tpexpr), loc));
        }