public override void VisitNewObjectExpression(NewObjectExpressionSyntax newObjectExpression, Void args) { base.VisitNewObjectExpression(newObjectExpression, args); CheckArguments(newObjectExpression.ConstructorType, newObjectExpression.Arguments); newObjectExpression.ValueSemantics = ValueSemantics.Move; }
public virtual void VisitNewObjectExpression(NewObjectExpressionSyntax newObjectExpression, A args) { VisitExpression(newObjectExpression.Constructor, args); foreach (var argument in newObjectExpression.Arguments) { VisitArgument(argument, args); } }
private DataType InferConstructorCallType(NewObjectExpressionSyntax expression) { var argumentTypes = expression.Arguments.Select(InferArgumentType).ToFixedList(); // TODO handle named constructors here var constructedType = (ObjectType)CheckAndEvaluateTypeExpression(expression.Constructor); var typeSymbol = GetSymbolForType(constructedType); var constructors = typeSymbol.ChildSymbols[SpecialName.New]; constructors = ResolveOverload(constructors, null, argumentTypes); switch (constructors.Count) { case 0: diagnostics.Add(NameBindingError.CouldNotBindConstructor(file, expression.Span)); expression.ConstructorSymbol = UnknownSymbol.Instance; expression.ConstructorType = DataType.Unknown; break; case 1: var constructorSymbol = constructors.Single(); expression.ConstructorSymbol = constructorSymbol; var constructorType = constructorSymbol.Type; expression.ConstructorType = constructorType; if (constructorType is FunctionType functionType) { foreach (var(arg, type) in expression.Arguments.Zip(functionType.ParameterTypes)) { InsertImplicitConversionIfNeeded(ref arg.Value, type); CheckArgumentTypeCompatibility(type, arg); } } break; default: diagnostics.Add(NameBindingError.AmbiguousConstructor(file, expression.Span)); expression.ConstructorSymbol = UnknownSymbol.Instance; expression.ConstructorType = DataType.Unknown; break; } return(expression.Type = constructedType.WithLifetime(Lifetime.Owned)); }