private IType MakeDestructuringAssignment(DestructuringAssignmentNode node, TypeInferrerVisitor visitor) { var tupleIValueSymbol = node.Left.Visit(visitor); var exprIValueSymbol = node.Right.Visit(visitor); return(visitor.Inferrer.FindMostGeneralType(tupleIValueSymbol, exprIValueSymbol)); }
private ISymbol MakeDestructuringAssignment(DestructuringAssignmentNode node, SymbolResolverVisitor visitor) { var left = node.Left.Visit(visitor); var right = node.Right.Visit(visitor); if (!left.IsAssignable()) { throw new SymbolException($"'{left.Name}' is a {left.GetType().Name} and cannot be used as a left-hand side in an assignment expression"); } if (!right.IsAssignable()) { throw new SymbolException($"'{right.Name}' is a {right.GetType().Name} and cannot be used as a right-hand side in an assignment expression"); } // On an assignment statement, we always return the left-hand side type return(left); }
private CheckedType MakeDestructuringAssignment(DestructuringAssignmentNode node, TypeCheckerVisitor checker) { var tupleCheckedType = node.Left.Visit(checker); var exprCheckedType = node.Right.Visit(checker); var tupleTypes = tupleCheckedType.TypeSymbol as Tuple; var exprTypes = exprCheckedType.TypeSymbol as Tuple; for (int i = 0; i < tupleTypes.Count; i++) { var varType = tupleTypes.Elements[i]; if (varType == null) { continue; } var varnode = node.Left.Items[i]; if (varnode.Expression is AccessorNode accessor && accessor.Parent != null) { var enc = accessor.Parent.Visit(checker); /*if (enc.ITypeSymbol is Class c) * throw new System.Exception($"An instance of {c.Name} '{c.ClassName}' is required to access member '{accessor.Target.Value}'");*/ } var leftHandSide = varnode.Expression.Visit(checker); if (leftHandSide.Symbol.Storage == Symbols.Storage.Constant) { throw new System.Exception($"Cannot change value of constant {leftHandSide.TypeSymbol.Name} '{leftHandSide.Symbol.Name}'"); } var exprType = exprTypes.Elements[i]; /*if (!varType.IsAssignableFrom(exprType)) * throw new System.Exception($"Cannot convert from {varType} to {exprType}");*/ } return(exprCheckedType); }
private MutabilityCheckResult CheckDestructuringAssignment(DestructuringAssignmentNode node, MutabilityCheckerVisitor checker) { for (int i = 0; i < node.Right.Items.Count; i++) { var varType = node.Right.Items[i]; if (varType == null) { continue; } var varnode = node.Left.Items[i]; var leftHandSide = varnode.Expression.Visit(checker); /*if (leftHandSide.Symbol.Storage == Symbols.Storage.Immutable) * throw new System.Exception($"Cannot change value of immutable variable {leftHandSide.Symbol.Name} '{leftHandSide.Symbol.Name}'");*/ } return(null); }