コード例 #1
0
        protected override void VisitAssignmentSyntax(AssignmentSyntax pNode)
        {
            base.VisitAssignmentSyntax(pNode);
            if (pNode.Value.Type == SmallTypeCache.NoValue)
            {
                CompilerErrors.ExpressionNoValue(pNode.Value.Span);
            }

            var isTuple = pNode.Value.Type.IsTuple;

            for (int i = 0; i < pNode.Variables.Count; i++)
            {
                //Check if we are assigning to a const variable
                if (_locals.TryGetVariable(pNode.Variables[i].Value, out LocalDefinition ld) && ld.IsConst)
                {
                    CompilerErrors.CannotAssignCost(pNode.Variables[i], pNode.Variables[i].Span);
                }

                var t = isTuple ? pNode.Value.Type.GetFieldType(i) : pNode.Value.Type;

                //We have to set the type of discards so the tuple is created properly
                if (SyntaxHelper.IsDiscard(pNode.Variables[i]))
                {
                    ((DiscardSyntax)pNode.Variables[i]).SetType(t);
                }
            }
        }