From e3346a77c7923f9c93018045c709c6e6642c7a8d Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Mon, 4 Nov 2019 00:04:45 +0330 Subject: [PATCH 01/41] Rebase target-typed-new branch on top of master --- .../Portable/Binder/Binder_Conversions.cs | 62 + .../Portable/Binder/Binder_Expressions.cs | 381 +- .../Portable/Binder/Binder_Operators.cs | 42 +- .../CSharp/Portable/Binder/Binder_Query.cs | 4 + .../Portable/Binder/Binder_Statements.cs | 7 + .../Portable/Binder/Binder_TupleOperators.cs | 17 +- .../Semantics/Conversions/Conversion.cs | 12 + .../Semantics/Conversions/ConversionKind.cs | 1 + .../Conversions/ConversionKindExtensions.cs | 1 + .../Semantics/Conversions/ConversionsBase.cs | 3 + .../OverloadResolution/AnalyzedArguments.cs | 20 + .../Portable/BoundTree/BoundExpression.cs | 1 + .../BoundTree/BoundExpressionExtensions.cs | 9 +- .../CSharp/Portable/BoundTree/BoundNodes.xml | 9 + .../CSharp/Portable/BoundTree/Formatting.cs | 5 + .../Portable/CSharpResources.Designer.cs | 48 +- .../CSharp/Portable/CSharpResources.resx | 18 +- .../CSharp/Portable/Errors/ErrorCode.cs | 8 +- .../CSharp/Portable/Errors/MessageID.cs | 5 + .../Portable/FlowAnalysis/AbstractFlowPass.cs | 5 + .../Portable/FlowAnalysis/NullableWalker.cs | 12 + .../Generated/BoundNodes.xml.Generated.cs | 83 + .../Portable/Generated/CSharp.Generated.g4 | 19 +- .../Syntax.xml.Internal.Generated.cs | 222 +- .../Generated/Syntax.xml.Main.Generated.cs | 24 + .../Generated/Syntax.xml.Syntax.Generated.cs | 112 +- .../Lowering/LocalRewriter/LocalRewriter.cs | 5 + .../CSharp/Portable/Parser/LanguageParser.cs | 93 +- .../CSharp/Portable/Parser/SyntaxParser.cs | 2 +- .../CSharp/Portable/PublicAPI.Unshipped.txt | 32 + .../Symbols/Source/ParameterHelpers.cs | 6 +- .../Source/SourceComplexParameterSymbol.cs | 2 +- .../CSharp/Portable/Syntax/Syntax.xml | 52 +- .../CSharp/Portable/Syntax/SyntaxKind.cs | 1 + .../Portable/xlf/CSharpResources.cs.xlf | 40 +- .../Portable/xlf/CSharpResources.de.xlf | 40 +- .../Portable/xlf/CSharpResources.es.xlf | 40 +- .../Portable/xlf/CSharpResources.fr.xlf | 40 +- .../Portable/xlf/CSharpResources.it.xlf | 40 +- .../Portable/xlf/CSharpResources.ja.xlf | 40 +- .../Portable/xlf/CSharpResources.ko.xlf | 40 +- .../Portable/xlf/CSharpResources.pl.xlf | 40 +- .../Portable/xlf/CSharpResources.pt-BR.xlf | 40 +- .../Portable/xlf/CSharpResources.ru.xlf | 40 +- .../Portable/xlf/CSharpResources.tr.xlf | 40 +- .../Portable/xlf/CSharpResources.zh-Hans.xlf | 40 +- .../Portable/xlf/CSharpResources.zh-Hant.xlf | 40 +- .../Emit/CodeGen/CodeGenTupleEqualityTests.cs | 8 +- ...perationTests_IObjectCreationExpression.cs | 1488 +++++++ .../Semantics/NullableReferenceTypesTests.cs | 19 +- .../Semantic/Semantics/SemanticErrorTests.cs | 16 +- .../Semantics/TargetTypedDefaultTests.cs | 120 +- .../TargetTypedObjectCreationTests.cs | 3758 +++++++++++++++++ .../Generated/Syntax.Test.xml.Generated.cs | 82 + .../Test/Syntax/Parsing/ParsingTests.cs | 2 +- .../TargetTypedObjectCreationParsingTests.cs | 568 +++ src/Test/Utilities/Portable/TestResource.resx | 1 + 57 files changed, 7431 insertions(+), 474 deletions(-) create mode 100644 src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs create mode 100644 src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs index 8942b402d7205..7a06867a67e47 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs @@ -124,6 +124,11 @@ protected BoundExpression CreateConversion( } } + if (conversion.IsObjectCreation) + { + return ConvertObjectCreationExpression((UnboundObjectCreationExpression)source, isCast, destination, diagnostics); + } + if (conversion.IsUserDefined) { // User-defined conversions are likely to be represented as multiple @@ -151,6 +156,63 @@ protected BoundExpression CreateConversion( { WasCompilerGenerated = wasCompilerGenerated }; } + private BoundExpression ConvertObjectCreationExpression(UnboundObjectCreationExpression node, bool isCast, TypeSymbol destination, DiagnosticBag diagnostics) + { + var arguments = AnalyzedArguments.GetInstance(node.Arguments, node.ArgumentRefKindsOpt, node.ArgumentNamesOpt); + BoundExpression expr = BindObjectCreationExpression(node, destination.StrippedType(), arguments, diagnostics); + if (destination.IsNullableType()) + { + // We manually create an ImplicitNullable conversion + // if the destination is nullable, in which case we + // target the underlying type e.g. `S? x = new();` + // is actually identical to `S? x = new S();`. + expr = new BoundConversion( + node.Syntax, + operand: expr, + conversion: new Conversion(ConversionKind.ImplicitNullable, Conversion.IdentityUnderlying), + @checked: false, + explicitCastInCode: isCast, + conversionGroupOpt: null, + constantValueOpt: expr.ConstantValue, + type: destination); + } + arguments.Free(); + return expr; + } + + private BoundExpression BindObjectCreationExpression(UnboundObjectCreationExpression node, TypeSymbol type, AnalyzedArguments arguments, DiagnosticBag diagnostics) + { + var syntax = node.Syntax; + switch (type.TypeKind) + { + case TypeKind.Struct: + case TypeKind.Class when !type.IsAnonymousType: // We don't want to enable object creation with unspeakable types + return BindClassCreationExpression(syntax, type.Name, typeNode: syntax, (NamedTypeSymbol)type, arguments, diagnostics, node.InitializerOpt); + case TypeKind.TypeParameter: + return BindTypeParameterCreationExpression(syntax, (TypeParameterSymbol)type, arguments, node.InitializerOpt, typeSyntax: syntax, diagnostics); + case TypeKind.Delegate: + return BindDelegateCreationExpression(syntax, (NamedTypeSymbol)type, arguments, node.InitializerOpt, diagnostics); + case TypeKind.Array: + case TypeKind.Enum: + case TypeKind.Class: + Error(diagnostics, ErrorCode.ERR_TypelessNewIllegalTargetType, syntax, type); + goto case TypeKind.Error; + case TypeKind.Interface: + Error(diagnostics, ErrorCode.ERR_NoNewAbstract, syntax, type); + goto case TypeKind.Error; + case TypeKind.Pointer: + Error(diagnostics, ErrorCode.ERR_UnsafeTypeInObjectCreation, syntax, type); + goto case TypeKind.Error; + case TypeKind.Dynamic: + Error(diagnostics, ErrorCode.ERR_NoConstructors, syntax, type); + goto case TypeKind.Error; + case TypeKind.Error: + return MakeBadExpressionForObjectCreation(syntax, type, arguments, node.InitializerOpt, typeSyntax: syntax, diagnostics); + case var v: + throw ExceptionUtilities.UnexpectedValue(v); + } + } + /// /// Rewrite the expressions in the switch expression arms to add a conversion to the destination type. /// diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 01be0a27069d2..1a57b0741ec4a 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -229,9 +229,9 @@ internal BoundExpression BindValue(ExpressionSyntax node, DiagnosticBag diagnost return CheckValue(result, valueKind, diagnostics); } - internal BoundExpression BindRValueWithoutTargetType(ExpressionSyntax node, DiagnosticBag diagnostics, bool reportDefaultMissingType = true) + internal BoundExpression BindRValueWithoutTargetType(ExpressionSyntax node, DiagnosticBag diagnostics, bool reportNoTargetType = true) { - return BindToNaturalType(BindValue(node, diagnostics, BindValueKind.RValue), diagnostics, reportDefaultMissingType); + return BindToNaturalType(BindValue(node, diagnostics, BindValueKind.RValue), diagnostics, reportNoTargetType); } internal BoundExpression BindToTypeForErrorRecovery(BoundExpression expression, TypeSymbol type = null) @@ -241,7 +241,7 @@ internal BoundExpression BindToTypeForErrorRecovery(BoundExpression expression, var discardedDiagnostics = DiagnosticBag.GetInstance(); var result = (!expression.NeedsToBeConverted() || expression.WasConverted) ? expression : - type is null ? BindToNaturalType(expression, discardedDiagnostics, reportDefaultMissingType: false) : + type is null ? BindToNaturalType(expression, discardedDiagnostics, reportNoTargetType: false) : GenerateConversionForAssignment(type, expression, discardedDiagnostics); discardedDiagnostics.Free(); return result; @@ -254,7 +254,7 @@ internal BoundExpression BindToTypeForErrorRecovery(BoundExpression expression, /// that such a conversion occurs when needed. It also handles tuple expressions which need to be /// converted to their own natural type because they may contain switch expressions. /// - internal BoundExpression BindToNaturalType(BoundExpression expression, DiagnosticBag diagnostics, bool reportDefaultMissingType = true) + internal BoundExpression BindToNaturalType(BoundExpression expression, DiagnosticBag diagnostics, bool reportNoTargetType = true) { BoundExpression result; switch (expression) @@ -278,7 +278,8 @@ internal BoundExpression BindToNaturalType(BoundExpression expression, Diagnosti sourceTuple.Syntax, sourceTuple, wasTargetTyped: false, - sourceTuple.Arguments.SelectAsArray(e => BindToNaturalType(e, diagnostics, reportDefaultMissingType)), + sourceTuple.Arguments.SelectAsArray( + (e, t) => t.self.BindToNaturalType(e, t.diagnostics, t.reportNoTargetType), (self: this, diagnostics, reportNoTargetType)), sourceTuple.ArgumentNamesOpt, sourceTuple.InferredNamesOpt, sourceTuple.Type, // same type to keep original element names @@ -286,7 +287,7 @@ internal BoundExpression BindToNaturalType(BoundExpression expression, Diagnosti break; case BoundDefaultLiteral defaultExpr: { - if (reportDefaultMissingType) + if (reportNoTargetType) { // In some cases, we let the caller report the error diagnostics.Add(ErrorCode.ERR_DefaultLiteralNoTargetType, defaultExpr.Syntax.GetLocation()); @@ -300,6 +301,16 @@ internal BoundExpression BindToNaturalType(BoundExpression expression, Diagnosti hasErrors: true).WithSuppression(defaultExpr.IsSuppressed); } break; + case UnboundObjectCreationExpression expr: + { + if (reportNoTargetType) + { + diagnostics.Add(ErrorCode.ERR_TypelessNewNoTargetType, expr.Syntax.GetLocation()); + } + + result = BindObjectCreationForErrorRecovery(expr, diagnostics); + } + break; default: result = expression; break; @@ -473,6 +484,8 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, Diagnostic return BindImplicitStackAllocArrayCreationExpression((ImplicitStackAllocArrayCreationExpressionSyntax)node, diagnostics); case SyntaxKind.ObjectCreationExpression: return BindObjectCreationExpression((ObjectCreationExpressionSyntax)node, diagnostics); + case SyntaxKind.ImplicitObjectCreationExpression: + return BindImplicitObjectCreationExpression((ImplicitObjectCreationExpressionSyntax)node, diagnostics); case SyntaxKind.IdentifierName: case SyntaxKind.GenericName: return BindIdentifier((SimpleNameSyntax)node, invoked, indexed, diagnostics); @@ -3901,6 +3914,20 @@ private BoundExpression BindConstructorInitializerCore( } } + private BoundExpression BindImplicitObjectCreationExpression(ImplicitObjectCreationExpressionSyntax node, DiagnosticBag diagnostics) + { + var arguments = AnalyzedArguments.GetInstance(); + BindArgumentsAndNames(node.ArgumentList, diagnostics, arguments, allowArglist: true); + var result = new UnboundObjectCreationExpression( + node, + arguments.Arguments.ToImmutable(), + arguments.Names.ToImmutableOrNull(), + arguments.RefKinds.ToImmutableOrNull(), + node.Initializer); + arguments.Free(); + return result; + } + protected BoundExpression BindObjectCreationExpression(ObjectCreationExpressionSyntax node, DiagnosticBag diagnostics) { var typeWithAnnotations = BindType(node.Type, diagnostics); @@ -3953,176 +3980,172 @@ protected BoundExpression BindObjectCreationExpression(ObjectCreationExpressionS private BoundExpression BindDelegateCreationExpression(ObjectCreationExpressionSyntax node, NamedTypeSymbol type, DiagnosticBag diagnostics) { - // Get the bound arguments and the argument names. AnalyzedArguments analyzedArguments = AnalyzedArguments.GetInstance(); + BindArgumentsAndNames(node.ArgumentList, diagnostics, analyzedArguments, isDelegateCreation: true); + var result = BindDelegateCreationExpression(node, type, analyzedArguments, node.Initializer, diagnostics); + analyzedArguments.Free(); + return result; + } - try + private BoundExpression BindDelegateCreationExpression(SyntaxNode node, NamedTypeSymbol type, AnalyzedArguments analyzedArguments, InitializerExpressionSyntax initializerOpt, DiagnosticBag diagnostics) + { + bool hasErrors = false; + if (analyzedArguments.HasErrors) { - BindArgumentsAndNames(node.ArgumentList, diagnostics, analyzedArguments, isDelegateCreation: true); + // Let's skip this part of further error checking without marking hasErrors = true here, + // as the argument could be an unbound lambda, and the error could come from inside. + // We'll check analyzedArguments.HasErrors again after we find if this is not the case. + } + else if (analyzedArguments.Arguments.Count == 0) + { + diagnostics.Add(ErrorCode.ERR_BadCtorArgCount, node.Location, type, 0); + hasErrors = true; + } + else if (analyzedArguments.Names.Count != 0 || analyzedArguments.RefKinds.Count != 0 || analyzedArguments.Arguments.Count != 1) + { + // Use a smaller span that excludes the parens. + var argSyntax = analyzedArguments.Arguments[0].Syntax; + var start = argSyntax.SpanStart; + var end = analyzedArguments.Arguments[analyzedArguments.Arguments.Count - 1].Syntax.Span.End; + var errorSpan = new TextSpan(start, end - start); - bool hasErrors = false; - if (analyzedArguments.HasErrors) - { - // Let's skip this part of further error checking without marking hasErrors = true here, - // as the argument could be an unbound lambda, and the error could come from inside. - // We'll check analyzedArguments.HasErrors again after we find if this is not the case. - } - else if (node.ArgumentList == null || analyzedArguments.Arguments.Count == 0) - { - diagnostics.Add(ErrorCode.ERR_BadCtorArgCount, node.Location, type, 0); - hasErrors = true; - } - else if (analyzedArguments.Names.Count != 0 || analyzedArguments.RefKinds.Count != 0 || analyzedArguments.Arguments.Count != 1) - { - // Use a smaller span that excludes the parens. - var argSyntax = analyzedArguments.Arguments[0].Syntax; - var start = argSyntax.SpanStart; - var end = analyzedArguments.Arguments[analyzedArguments.Arguments.Count - 1].Syntax.Span.End; - var errorSpan = new TextSpan(start, end - start); + var loc = new SourceLocation(argSyntax.SyntaxTree, errorSpan); - var loc = new SourceLocation(argSyntax.SyntaxTree, errorSpan); + diagnostics.Add(ErrorCode.ERR_MethodNameExpected, loc); + hasErrors = true; + } - diagnostics.Add(ErrorCode.ERR_MethodNameExpected, loc); - hasErrors = true; - } + if (initializerOpt != null) + { + Error(diagnostics, ErrorCode.ERR_ObjectOrCollectionInitializerWithDelegateCreation, node); + hasErrors = true; + } - if (node.Initializer != null) - { - Error(diagnostics, ErrorCode.ERR_ObjectOrCollectionInitializerWithDelegateCreation, node); - hasErrors = true; - } + BoundExpression argument = BindToNaturalType(analyzedArguments.Arguments.Count >= 1 ? analyzedArguments.Arguments[0] : null, diagnostics); - BoundExpression argument = BindToNaturalType(analyzedArguments.Arguments.Count >= 1 ? analyzedArguments.Arguments[0] : null, diagnostics); + if (hasErrors) + { + // skip the rest of this binding + } - if (hasErrors) + // There are four cases for a delegate creation expression (7.6.10.5): + // 1. An anonymous function is treated as a conversion from the anonymous function to the delegate type. + else if (argument is UnboundLambda unboundLambda) + { + // analyzedArguments.HasErrors could be true, + // but here the argument is an unbound lambda, the error comes from inside + // eg: new Action(x => x.) + // We should try to bind it anyway in order for intellisense to work. + + HashSet useSiteDiagnostics = null; + var conversion = this.Conversions.ClassifyConversionFromExpression(unboundLambda, type, ref useSiteDiagnostics); + diagnostics.Add(node, useSiteDiagnostics); + // Attempting to make the conversion caches the diagnostics and the bound state inside + // the unbound lambda. Fetch the result from the cache. + BoundLambda boundLambda = unboundLambda.Bind(type); + + if (!conversion.IsImplicit || !conversion.IsValid) { - // skip the rest of this binding + GenerateImplicitConversionError(diagnostics, unboundLambda.Syntax, conversion, unboundLambda, type); } - - // There are four cases for a delegate creation expression (7.6.10.5): - // 1. An anonymous function is treated as a conversion from the anonymous function to the delegate type. - else if (argument is UnboundLambda) + else { - // analyzedArguments.HasErrors could be true, - // but here the argument is an unbound lambda, the error comes from inside - // eg: new Action(x => x.) - // We should try to bind it anyway in order for intellisense to work. - - UnboundLambda unboundLambda = (UnboundLambda)argument; - HashSet useSiteDiagnostics = null; - var conversion = this.Conversions.ClassifyConversionFromExpression(unboundLambda, type, ref useSiteDiagnostics); - diagnostics.Add(node, useSiteDiagnostics); - // Attempting to make the conversion caches the diagnostics and the bound state inside - // the unbound lambda. Fetch the result from the cache. - BoundLambda boundLambda = unboundLambda.Bind(type); + // We're not going to produce an error, but it is possible that the conversion from + // the lambda to the delegate type produced a warning, which we have not reported. + // Instead, we've cached it in the bound lambda. Report it now. + diagnostics.AddRange(boundLambda.Diagnostics); + } - if (!conversion.IsImplicit || !conversion.IsValid) - { - GenerateImplicitConversionError(diagnostics, unboundLambda.Syntax, conversion, unboundLambda, type); - } - else - { - // We're not going to produce an error, but it is possible that the conversion from - // the lambda to the delegate type produced a warning, which we have not reported. - // Instead, we've cached it in the bound lambda. Report it now. - diagnostics.AddRange(boundLambda.Diagnostics); - } + // Just stuff the bound lambda into the delegate creation expression. When we lower the lambda to + // its method form we will rewrite this expression to refer to the method. - // Just stuff the bound lambda into the delegate creation expression. When we lower the lambda to - // its method form we will rewrite this expression to refer to the method. + return new BoundDelegateCreationExpression(node, boundLambda, methodOpt: null, isExtensionMethod: false, type: type, hasErrors: !conversion.IsImplicit); + } - return new BoundDelegateCreationExpression(node, boundLambda, methodOpt: null, isExtensionMethod: false, type: type, hasErrors: !conversion.IsImplicit); - } + else if (analyzedArguments.HasErrors) + { + // There is no hope, skip. + } - else if (analyzedArguments.HasErrors) - { - // There is no hope, skip. - } + // 2. A method group + else if (argument.Kind == BoundKind.MethodGroup) + { + Conversion conversion; + BoundMethodGroup methodGroup = (BoundMethodGroup)argument; + hasErrors = MethodGroupConversionDoesNotExistOrHasErrors(methodGroup, type, node.Location, diagnostics, out conversion); + methodGroup = FixMethodGroupWithTypeOrValue(methodGroup, conversion, diagnostics); + return new BoundDelegateCreationExpression(node, methodGroup, conversion.Method, conversion.IsExtensionMethod, type, hasErrors); + } - // 2. A method group - else if (argument.Kind == BoundKind.MethodGroup) - { - Conversion conversion; - BoundMethodGroup methodGroup = (BoundMethodGroup)argument; - hasErrors = MethodGroupConversionDoesNotExistOrHasErrors(methodGroup, type, node.Location, diagnostics, out conversion); - methodGroup = FixMethodGroupWithTypeOrValue(methodGroup, conversion, diagnostics); - return new BoundDelegateCreationExpression(node, methodGroup, conversion.Method, conversion.IsExtensionMethod, type, hasErrors); - } + else if ((object)argument.Type == null) + { + diagnostics.Add(ErrorCode.ERR_MethodNameExpected, argument.Syntax.Location); + } - else if ((object)argument.Type == null) - { - diagnostics.Add(ErrorCode.ERR_MethodNameExpected, argument.Syntax.Location); - } + // 3. A value of the compile-time type dynamic (which is dynamically case 4), or + else if (argument.HasDynamicType()) + { + return new BoundDelegateCreationExpression(node, argument, methodOpt: null, isExtensionMethod: false, type: type); + } - // 3. A value of the compile-time type dynamic (which is dynamically case 4), or - else if (argument.HasDynamicType()) + // 4. A delegate type. + else if (argument.Type.TypeKind == TypeKind.Delegate) + { + var sourceDelegate = (NamedTypeSymbol)argument.Type; + MethodGroup methodGroup = MethodGroup.GetInstance(); + try { - return new BoundDelegateCreationExpression(node, argument, methodOpt: null, isExtensionMethod: false, type: type); - } + if (ReportDelegateInvokeUseSiteDiagnostic(diagnostics, argument.Type, node: node)) + { + // We want failed "new" expression to use the constructors as their symbols. + return new BoundBadExpression(node, LookupResultKind.NotInvocable, StaticCast.From(type.InstanceConstructors), ImmutableArray.Create(argument), type); + } - // 4. A delegate type. - else if (argument.Type.TypeKind == TypeKind.Delegate) - { - var sourceDelegate = (NamedTypeSymbol)argument.Type; - MethodGroup methodGroup = MethodGroup.GetInstance(); - try + methodGroup.PopulateWithSingleMethod(argument, sourceDelegate.DelegateInvokeMethod); + HashSet useSiteDiagnostics = null; + Conversion conv = Conversions.MethodGroupConversion(argument.Syntax, methodGroup, type, ref useSiteDiagnostics); + diagnostics.Add(node, useSiteDiagnostics); + if (!conv.Exists) { - if (ReportDelegateInvokeUseSiteDiagnostic(diagnostics, argument.Type, node: node)) + var boundMethodGroup = new BoundMethodGroup( + argument.Syntax, default, WellKnownMemberNames.DelegateInvokeName, ImmutableArray.Create(sourceDelegate.DelegateInvokeMethod), + sourceDelegate.DelegateInvokeMethod, null, BoundMethodGroupFlags.None, argument, LookupResultKind.Viable); + if (!Conversions.ReportDelegateMethodGroupDiagnostics(this, boundMethodGroup, type, diagnostics)) { - // We want failed "new" expression to use the constructors as their symbols. - return new BoundBadExpression(node, LookupResultKind.NotInvocable, StaticCast.From(type.InstanceConstructors), ImmutableArray.Create(argument), type); + // If we could not produce a more specialized diagnostic, we report + // No overload for '{0}' matches delegate '{1}' + diagnostics.Add(ErrorCode.ERR_MethDelegateMismatch, node.Location, + sourceDelegate.DelegateInvokeMethod, + type); } + } + else + { + Debug.Assert(!conv.IsExtensionMethod); + Debug.Assert(conv.IsValid); // i.e. if it exists, then it is valid. - methodGroup.PopulateWithSingleMethod(argument, sourceDelegate.DelegateInvokeMethod); - HashSet useSiteDiagnostics = null; - Conversion conv = Conversions.MethodGroupConversion(argument.Syntax, methodGroup, type, ref useSiteDiagnostics); - diagnostics.Add(node, useSiteDiagnostics); - if (!conv.Exists) + if (!this.MethodGroupConversionHasErrors(argument.Syntax, conv, argument, conv.IsExtensionMethod, type, diagnostics)) { - var boundMethodGroup = new BoundMethodGroup( - argument.Syntax, default, WellKnownMemberNames.DelegateInvokeName, ImmutableArray.Create(sourceDelegate.DelegateInvokeMethod), - sourceDelegate.DelegateInvokeMethod, null, BoundMethodGroupFlags.None, argument, LookupResultKind.Viable); - if (!Conversions.ReportDelegateMethodGroupDiagnostics(this, boundMethodGroup, type, diagnostics)) - { - // If we could not produce a more specialized diagnostic, we report - // No overload for '{0}' matches delegate '{1}' - diagnostics.Add(ErrorCode.ERR_MethDelegateMismatch, node.Location, - sourceDelegate.DelegateInvokeMethod, - type); - } + // we do not place the "Invoke" method in the node, indicating that it did not appear in source. + return new BoundDelegateCreationExpression(node, argument, methodOpt: null, isExtensionMethod: false, type: type); } - else - { - Debug.Assert(!conv.IsExtensionMethod); - Debug.Assert(conv.IsValid); // i.e. if it exists, then it is valid. - - if (!this.MethodGroupConversionHasErrors(argument.Syntax, conv, argument, conv.IsExtensionMethod, type, diagnostics)) - { - // we do not place the "Invoke" method in the node, indicating that it did not appear in source. - return new BoundDelegateCreationExpression(node, argument, methodOpt: null, isExtensionMethod: false, type: type); - } - } - } - finally - { - methodGroup.Free(); } } - - // Not a valid delegate creation expression - else + finally { - diagnostics.Add(ErrorCode.ERR_MethodNameExpected, argument.Syntax.Location); + methodGroup.Free(); } - - // Note that we want failed "new" expression to use the constructors as their symbols. - var childNodes = BuildArgumentsForErrorRecovery(analyzedArguments); - return new BoundBadExpression(node, LookupResultKind.OverloadResolutionFailure, StaticCast.From(type.InstanceConstructors), childNodes, type); } - finally + + // Not a valid delegate creation expression + else { - analyzedArguments.Free(); + diagnostics.Add(ErrorCode.ERR_MethodNameExpected, argument.Syntax.Location); } + + // Note that we want failed "new" expression to use the constructors as their symbols. + var childNodes = BuildArgumentsForErrorRecovery(analyzedArguments); + return new BoundBadExpression(node, LookupResultKind.OverloadResolutionFailure, StaticCast.From(type.InstanceConstructors), childNodes, type); } private BoundExpression BindClassCreationExpression(ObjectCreationExpressionSyntax node, NamedTypeSymbol type, string typeName, DiagnosticBag diagnostics, TypeSymbol initializerType = null) @@ -4155,15 +4178,28 @@ private BoundExpression BindClassCreationExpression(ObjectCreationExpressionSynt } } + internal BoundExpression BindObjectCreationForErrorRecovery(UnboundObjectCreationExpression node, DiagnosticBag diagnostics) + { + var arguments = AnalyzedArguments.GetInstance(node.Arguments, node.ArgumentRefKindsOpt, node.ArgumentNamesOpt); + var result = MakeBadExpressionForObjectCreation(node.Syntax, CreateErrorType(), arguments, node.InitializerOpt, typeSyntax: node.Syntax, diagnostics); + arguments.Free(); + return result; + } + private BoundExpression MakeBadExpressionForObjectCreation(ObjectCreationExpressionSyntax node, TypeSymbol type, AnalyzedArguments analyzedArguments, DiagnosticBag diagnostics) + { + return MakeBadExpressionForObjectCreation(node, type, analyzedArguments, node.Initializer, node.Type, diagnostics); + } + + private BoundExpression MakeBadExpressionForObjectCreation(SyntaxNode node, TypeSymbol type, AnalyzedArguments analyzedArguments, InitializerExpressionSyntax initializerOpt, SyntaxNode typeSyntax, DiagnosticBag diagnostics) { var children = ArrayBuilder.GetInstance(); children.AddRange(BuildArgumentsForErrorRecovery(analyzedArguments)); - if (node.Initializer != null) + if (initializerOpt != null) { - var boundInitializer = BindInitializerExpression(syntax: node.Initializer, + var boundInitializer = BindInitializerExpression(syntax: initializerOpt, type: type, - typeSyntax: node.Type, + typeSyntax: typeSyntax, diagnostics: diagnostics); children.Add(boundInitializer); } @@ -4900,9 +4936,9 @@ private bool IsConstructorAccessible(MethodSymbol constructor, ref HashSet 0; - - try + private BoundExpression BindTypeParameterCreationExpression(SyntaxNode node, TypeParameterSymbol typeParameter, AnalyzedArguments analyzedArguments, InitializerExpressionSyntax initializerOpt, SyntaxNode typeSyntax, DiagnosticBag diagnostics) + { + if (!typeParameter.HasConstructorConstraint && !typeParameter.IsValueType) { - if (!typeParameter.HasConstructorConstraint && !typeParameter.IsValueType) - { - diagnostics.Add(ErrorCode.ERR_NoNewTyvar, node.Location, typeParameter); - } - else if (hasArguments) - { - diagnostics.Add(ErrorCode.ERR_NewTyvarWithArgs, node.Location, typeParameter); - } - else - { - var boundInitializerOpt = node.Initializer == null ? - null : - BindInitializerExpression( - syntax: node.Initializer, - type: typeParameter, - typeSyntax: node.Type, - diagnostics: diagnostics); - return new BoundNewT(node, boundInitializerOpt, typeParameter); - } - - return MakeBadExpressionForObjectCreation(node, typeParameter, analyzedArguments, diagnostics); + diagnostics.Add(ErrorCode.ERR_NoNewTyvar, node.Location, typeParameter); } - finally + else if (analyzedArguments.Arguments.Count > 0) { - analyzedArguments.Free(); + diagnostics.Add(ErrorCode.ERR_NewTyvarWithArgs, node.Location, typeParameter); + } + else + { + var boundInitializerOpt = initializerOpt == null ? + null : + BindInitializerExpression( + syntax: initializerOpt, + type: typeParameter, + typeSyntax: typeSyntax, + diagnostics: diagnostics); + return new BoundNewT(node, boundInitializerOpt, typeParameter); } + + return MakeBadExpressionForObjectCreation(node, typeParameter, analyzedArguments, initializerOpt, typeSyntax, diagnostics); } /// @@ -5740,7 +5773,7 @@ private BoundExpression BindMemberAccessWithBoundLeft( // No member accesses on default if (boundLeft.IsLiteralDefault()) { - DiagnosticInfo diagnosticInfo = new CSDiagnosticInfo(ErrorCode.ERR_BadUnaryOp, SyntaxFacts.GetText(operatorToken.Kind()), "default"); + DiagnosticInfo diagnosticInfo = new CSDiagnosticInfo(ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, SyntaxFacts.GetText(operatorToken.Kind()), boundLeft.Display); diagnostics.Add(new CSDiagnostic(diagnosticInfo, operatorToken.GetLocation())); return BadExpression(node, boundLeft); } diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs index b572635ee0d96..c26b123f39aa8 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs @@ -583,8 +583,8 @@ private BoundExpression BindSimpleBinaryOperator(BinaryExpressionSyntax node, Di { // If we found an operator, we'll have given the `default` literal a type. // Otherwise, we'll have reported the problem in ReportBinaryOperatorError. - resultLeft = BindToNaturalType(resultLeft, diagnostics, reportDefaultMissingType: false); - resultRight = BindToNaturalType(resultRight, diagnostics, reportDefaultMissingType: false); + resultLeft = BindToNaturalType(resultLeft, diagnostics, reportNoTargetType: false); + resultRight = BindToNaturalType(resultRight, diagnostics, reportNoTargetType: false); } hasErrors = hasErrors || resultConstant != null && resultConstant.IsBad; @@ -649,8 +649,8 @@ private bool BindSimpleBinaryOperatorParts(BinaryExpressionSyntax node, Diagnost { resultSignature = signature; HashSet useSiteDiagnostics = null; - bool leftDefault = left.IsLiteralDefault(); - bool rightDefault = right.IsLiteralDefault(); + bool leftDefault = left.IsLiteralDefaultOrTypelessNew(); + bool rightDefault = right.IsLiteralDefaultOrTypelessNew(); foundOperator = !isObjectEquality || BuiltInOperators.IsValidObjectEquality(Conversions, leftType, leftNull, leftDefault, rightType, rightNull, rightDefault, ref useSiteDiagnostics); diagnostics.Add(node, useSiteDiagnostics); } @@ -695,18 +695,20 @@ private static void ReportBinaryOperatorError(ExpressionSyntax node, DiagnosticB { bool leftDefault = left.IsLiteralDefault(); bool rightDefault = right.IsLiteralDefault(); - if ((operatorToken.Kind() == SyntaxKind.EqualsEqualsToken || operatorToken.Kind() == SyntaxKind.ExclamationEqualsToken)) + if (operatorToken.Kind() != SyntaxKind.EqualsEqualsToken && operatorToken.Kind() != SyntaxKind.ExclamationEqualsToken) { - if (leftDefault && rightDefault) + if (leftDefault || rightDefault) { - Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnDefault, node, operatorToken.Text); + // other than == and !=, binary operators are disallowed on `default` literal + Error(diagnostics, ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, node, operatorToken.Text, "default"); return; } } - else if (leftDefault || rightDefault) + + if ((leftDefault || left.IsTypelessNew()) && + (rightDefault || right.IsTypelessNew())) { - // other than == and !=, binary operators are disallowed on `default` literal - Error(diagnostics, ErrorCode.ERR_BadOpOnNullOrDefault, node, operatorToken.Text, "default"); + Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnDefaultOrNew, node, operatorToken.Text, left.Display, right.Display); return; } @@ -1109,7 +1111,7 @@ private TypeSymbol GetBinaryOperatorErrorType(BinaryOperatorKind kind, Diagnosti private BinaryOperatorAnalysisResult BinaryOperatorOverloadResolution(BinaryOperatorKind kind, BoundExpression left, BoundExpression right, CSharpSyntaxNode node, DiagnosticBag diagnostics, out LookupResultKind resultKind, out ImmutableArray originalUserDefinedOperators) { - if (!IsDefaultLiteralAllowedInBinaryOperator(kind, left, right)) + if (!IsDefaultLiteralOrNewAllowedInBinaryOperator(kind, left, right)) { resultKind = LookupResultKind.OverloadResolutionFailure; originalUserDefinedOperators = default(ImmutableArray); @@ -1178,8 +1180,20 @@ private void ReportObsoleteAndFeatureAvailabilityDiagnostics(MethodSymbol operat } } - private bool IsDefaultLiteralAllowedInBinaryOperator(BinaryOperatorKind kind, BoundExpression left, BoundExpression right) + private bool IsDefaultLiteralOrNewAllowedInBinaryOperator(BinaryOperatorKind kind, BoundExpression left, BoundExpression right) { + // The default literal is only allowed with equality operators + // and both operands cannot be typeless at the same time. + if (left.IsTypelessNew()) + { + return !right.IsLiteralDefaultOrTypelessNew(); + } + + if (right.IsTypelessNew()) + { + return !left.IsLiteralDefault(); + } + bool isEquality = kind == BinaryOperatorKind.Equal || kind == BinaryOperatorKind.NotEqual; if (isEquality) { @@ -2308,7 +2322,7 @@ private BoundExpression BindUnaryOperatorCore(CSharpSyntaxNode node, string oper { // Dev10 does not allow unary prefix operators to be applied to the null literal // (or other typeless expressions). - Error(diagnostics, ErrorCode.ERR_BadOpOnNullOrDefault, node, operatorText, operand.Display); + Error(diagnostics, ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, node, operatorText, operand.Display); } // If the operand is bad, avoid generating cascading errors. @@ -3414,7 +3428,7 @@ private BoundExpression BindNullCoalescingOperator(BinaryExpressionSyntax node, // The specification does not permit the left hand side to be a default literal if (leftOperand.IsLiteralDefault()) { - Error(diagnostics, ErrorCode.ERR_BadOpOnNullOrDefault, node, node.OperatorToken.Text, "default"); + Error(diagnostics, ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, node, node.OperatorToken.Text, "default"); return new BoundNullCoalescingOperator(node, leftOperand, rightOperand, Conversion.NoConversion, BoundNullCoalescingOperatorResultKind.NoCommonType, CreateErrorType(), hasErrors: true); diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Query.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Query.cs index 41d223106a57b..974b3fe5503df 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Query.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Query.cs @@ -735,6 +735,10 @@ protected BoundCall MakeQueryInvocation(CSharpSyntaxNode node, BoundExpression r { diagnostics.Add(ErrorCode.ERR_DefaultLiteralNotValid, node.Location); } + else if (ultimateReceiver.IsTypelessNew()) + { + diagnostics.Add(ErrorCode.ERR_TypelessNewNotValid, node.Location); + } else if (ultimateReceiver.Kind == BoundKind.NamespaceExpression) { diagnostics.Add(ErrorCode.ERR_BadSKunknown, ultimateReceiver.Syntax.Location, ultimateReceiver.Syntax, MessageID.IDS_SK_NAMESPACE.Localize()); diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs index df7477a72051e..e8e445e6038d3 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs @@ -368,6 +368,13 @@ internal BoundStatement BindPossibleEmbeddedStatement(StatementSyntax node, Diag private BoundExpression BindThrownExpression(ExpressionSyntax exprSyntax, DiagnosticBag diagnostics, ref bool hasErrors) { var boundExpr = BindValue(exprSyntax, diagnostics, BindValueKind.RValue); + if (boundExpr.IsTypelessNew()) + { + // NOTE This only disallows direct usage. One can simply bypass this by wrapping new() in a switch expression + diagnostics.Add(ErrorCode.ERR_TypelessNewNotValid, exprSyntax.Location); + hasErrors = true; + } + if (Compilation.LanguageVersion < MessageID.IDS_FeatureSwitchExpression.RequiredVersion()) { // This is the pre-C# 8 algorithm for binding a thrown expression. diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs b/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs index 61acfef4645f4..eb185517d371c 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs @@ -44,7 +44,7 @@ private BoundExpression ApplyConvertedTypes(BoundExpression expr, TupleBinaryOpe var multiple = (TupleBinaryOperatorInfo.Multiple)@operator; if (multiple.Operators.Length == 0) { - return BindToNaturalType(expr, diagnostics, reportDefaultMissingType: false); + return BindToNaturalType(expr, diagnostics, reportNoTargetType: false); } ImmutableArray arguments = tuple.Arguments; @@ -62,7 +62,7 @@ private BoundExpression ApplyConvertedTypes(BoundExpression expr, TupleBinaryOpe } // This element isn't getting a converted type - return BindToNaturalType(expr, diagnostics, reportDefaultMissingType: false); + return BindToNaturalType(expr, diagnostics, reportNoTargetType: false); } // We were able to determine a converted type (for this tuple literal or element), we can just convert to it @@ -194,8 +194,8 @@ private TupleBinaryOperatorInfo.Multiple BindTupleBinaryOperatorNestedInfo(Binar left = GiveTupleTypeToDefaultLiteralIfNeeded(left, right.Type); right = GiveTupleTypeToDefaultLiteralIfNeeded(right, left.Type); - if ((left.Type is null && left.IsLiteralDefault()) || - (right.Type is null && right.IsLiteralDefault())) + if ((left.Type is null && left.IsLiteralDefaultOrTypelessNew()) || + (right.Type is null && right.IsLiteralDefaultOrTypelessNew())) { Error(diagnostics, ErrorCode.ERR_AmbigBinaryOps, node, node.OperatorToken.Text, left.Display, right.Display); return TupleBinaryOperatorInfo.Multiple.ErrorInstance; @@ -324,14 +324,15 @@ internal static BoundExpression GiveTupleTypeToDefaultLiteralIfNeeded(BoundExpre private static bool IsTupleBinaryOperation(BoundExpression left, BoundExpression right) { - bool leftDefault = left.IsLiteralDefault(); - bool rightDefault = right.IsLiteralDefault(); - if (leftDefault && rightDefault) + bool leftDefaultOrNew = left.IsLiteralDefaultOrTypelessNew(); + bool rightDefaultOrNew = right.IsLiteralDefaultOrTypelessNew(); + if (leftDefaultOrNew && rightDefaultOrNew) { return false; } - return (GetTupleCardinality(left) > 1 || leftDefault) && (GetTupleCardinality(right) > 1 || rightDefault); + return (GetTupleCardinality(left) > 1 || leftDefaultOrNew) && + (GetTupleCardinality(right) > 1 || rightDefaultOrNew); } private static int GetTupleCardinality(BoundExpression expr) diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversion.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversion.cs index e9eb5ee675de7..5f77916e69321 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversion.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversion.cs @@ -221,6 +221,7 @@ internal static Conversion GetTrivialConversion(ConversionKind kind) internal static Conversion ImplicitReference => new Conversion(ConversionKind.ImplicitReference); internal static Conversion ImplicitEnumeration => new Conversion(ConversionKind.ImplicitEnumeration); internal static Conversion ImplicitThrow => new Conversion(ConversionKind.ImplicitThrow); + internal static Conversion ObjectCreation => new Conversion(ConversionKind.ObjectCreation); internal static Conversion AnonymousFunction => new Conversion(ConversionKind.AnonymousFunction); internal static Conversion Boxing => new Conversion(ConversionKind.Boxing); internal static Conversion NullLiteral => new Conversion(ConversionKind.NullLiteral); @@ -517,6 +518,17 @@ public bool IsThrow } } + /// + /// Returns true if the conversion is an implicit object creation expression conversion. + /// + internal bool IsObjectCreation + { + get + { + return Kind == ConversionKind.ObjectCreation; + } + } + /// /// Returns true if the conversion is an implicit switch expression conversion. /// diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKind.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKind.cs index d300b2d9752a8..9fe02483042a4 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKind.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKind.cs @@ -54,5 +54,6 @@ internal enum ConversionKind : byte PinnedObjectToPointer, DefaultLiteral, // a conversion from a `default` literal to any type + ObjectCreation, // a conversion from a `new()` expression to any type } } diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs index 81bf08e1ea60c..0a72337131d2b 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs @@ -48,6 +48,7 @@ public static bool IsImplicitConversion(this ConversionKind conversionKind) case Deconstruction: case StackAllocToPointerType: case StackAllocToSpanType: + case ObjectCreation: return true; case ExplicitNumeric: diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs index 1701dbc26c63b..8c559173a5d08 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs @@ -922,6 +922,9 @@ private Conversion ClassifyImplicitBuiltInConversionFromExpression(BoundExpressi case BoundKind.ThrowExpression: return Conversion.ImplicitThrow; + + case BoundKind.UnboundObjectCreationExpression: + return Conversion.ObjectCreation; } return Conversion.NoConversion; diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/AnalyzedArguments.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/AnalyzedArguments.cs index 242355e4d3ae4..ffd112b8e02e4 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/AnalyzedArguments.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/AnalyzedArguments.cs @@ -138,6 +138,26 @@ public static AnalyzedArguments GetInstance(AnalyzedArguments original) return instance; } + public static AnalyzedArguments GetInstance( + ImmutableArray arguments, + ImmutableArray argumentRefKindsOpt, + ImmutableArray argumentNamesOpt) + { + var instance = GetInstance(); + instance.Arguments.AddRange(arguments); + if (!argumentRefKindsOpt.IsDefault) + { + instance.RefKinds.AddRange(argumentRefKindsOpt); + } + + if (!argumentNamesOpt.IsDefault) + { + instance.Names.AddRange(argumentNamesOpt); + } + + return instance; + } + public void Free() { this.Clear(); diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs index 8b0adbbbc9bd0..b493e62bcd2b5 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs @@ -54,6 +54,7 @@ internal bool NeedsToBeConverted() { case BoundKind.TupleLiteral: case BoundKind.UnconvertedSwitchExpression: + case BoundKind.UnboundObjectCreationExpression: return true; #if DEBUG case BoundKind.Local when !WasConverted: diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundExpressionExtensions.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundExpressionExtensions.cs index a2d9ee6932de8..6af2bee07e821 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundExpressionExtensions.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundExpressionExtensions.cs @@ -43,9 +43,14 @@ public static bool IsLiteralDefault(this BoundExpression node) return node.Kind == BoundKind.DefaultLiteral; } - public static bool IsLiteralNullOrDefault(this BoundExpression node) + public static bool IsTypelessNew(this BoundExpression node) { - return node.IsLiteralNull() || node.IsLiteralDefault(); + return node.Kind == BoundKind.UnboundObjectCreationExpression; + } + + public static bool IsLiteralDefaultOrTypelessNew(this BoundExpression node) + { + return node.IsLiteralDefault() || node.IsTypelessNew(); } // returns true when expression has no side-effects and produces diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml index 7ab80d6d14b7f..f3d8df5434bd2 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml @@ -1541,6 +1541,15 @@ + + + + + + + + + From fc55e5ef4321bd3a555408c443f4a4f82f04b18d Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Wed, 18 Dec 2019 23:38:11 +0330 Subject: [PATCH 11/41] Revert code --- src/Compilers/CSharp/Portable/Parser/LanguageParser.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 43ddf53adb3cc..399843f756d6c 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -5688,6 +5688,7 @@ private ScanTypeFlags ScanNamedTypePart(out SyntaxToken lastTokenOfType) private ScanTypeFlags ScanType(ParseTypeMode mode, out SyntaxToken lastTokenOfType) { + Debug.Assert(mode != ParseTypeMode.NewExpression); ScanTypeFlags result; if (this.CurrentToken.Kind == SyntaxKind.RefKeyword) From 8e6d3e054142c947765e996ae6d9953f3acbbedf Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 19 Dec 2019 19:35:34 +0330 Subject: [PATCH 12/41] Explicit type parsing mode to avoid superfluous diagnostics --- src/Compilers/CSharp/Portable/Parser/LanguageParser.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 399843f756d6c..311ef8b7abbb5 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -5902,6 +5902,7 @@ private enum ParseTypeMode AfterIs, DefinitePattern, AfterOut, + AfterRef, AfterTupleComma, AsExpression, NewExpression, @@ -5922,7 +5923,7 @@ private TypeSyntax ParseType(ParseTypeMode mode = ParseTypeMode.Normal) readonlyKeyword = this.CheckFeatureAvailability(readonlyKeyword, MessageID.IDS_FeatureReadOnlyReferences); } - var type = ParseTypeCore(mode); + var type = ParseTypeCore(ParseTypeMode.AfterRef); return _syntaxFactory.RefType(refKeyword, readonlyKeyword, type); } @@ -5953,6 +5954,7 @@ private TypeSyntax ParseTypeCore(ParseTypeMode mode) case ParseTypeMode.AsExpression: case ParseTypeMode.Normal: case ParseTypeMode.Parameter: + case ParseTypeMode.AfterRef: nameOptions = NameOptions.None; break; default: From ccee382853716b6b4f7575b0169df24b047831f5 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 19 Dec 2019 19:39:45 +0330 Subject: [PATCH 13/41] Bind to natrual type so the node cannot sneak into a later pass --- src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs | 1 + src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs | 2 ++ src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs index 5429e78abb3fa..1059926879a85 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs @@ -1548,6 +1548,7 @@ private BoundExpression BindNameofOperatorInternal(InvocationExpressionSyntax no } } + boundArgument = BindToNaturalType(boundArgument, diagnostics, reportNoTargetType: false); return new BoundNameOfOperator(node, boundArgument, ConstantValue.Create(name), Compilation.GetSpecialType(SpecialType.System_String)); } diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs index c26b123f39aa8..9ccb29a62f66a 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs @@ -3870,6 +3870,8 @@ private BoundExpression BindConditionalOperator(ConditionalExpressionSyntax node hasErrors = constantValue != null && constantValue.IsBad; } + trueExpr = BindToNaturalType(trueExpr, diagnostics, reportNoTargetType: false); + falseExpr = BindToNaturalType(falseExpr, diagnostics, reportNoTargetType: false); return new BoundConditionalOperator(node, isRef, condition, trueExpr, falseExpr, constantValue, type, hasErrors); } diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs index bfdd24e0e83a7..e387bc745919a 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs @@ -2718,7 +2718,7 @@ public override BoundNode VisitDefaultExpression(BoundDefaultExpression node) public override BoundNode VisitUnboundObjectCreationExpression(UnboundObjectCreationExpression node) { - return null; + throw ExceptionUtilities.Unreachable; } public override BoundNode VisitTypeOfOperator(BoundTypeOfOperator node) From 067bf52409aaff69942d87487436d218042b872b Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 19 Dec 2019 20:00:48 +0330 Subject: [PATCH 14/41] Clarify comment on binary operator resolution --- src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs index 9ccb29a62f66a..99e639ef8c91d 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs @@ -1111,7 +1111,7 @@ private TypeSymbol GetBinaryOperatorErrorType(BinaryOperatorKind kind, Diagnosti private BinaryOperatorAnalysisResult BinaryOperatorOverloadResolution(BinaryOperatorKind kind, BoundExpression left, BoundExpression right, CSharpSyntaxNode node, DiagnosticBag diagnostics, out LookupResultKind resultKind, out ImmutableArray originalUserDefinedOperators) { - if (!IsDefaultLiteralOrNewAllowedInBinaryOperator(kind, left, right)) + if (!IsTypelessExpressionAllowedInBinaryOperator(kind, left, right)) { resultKind = LookupResultKind.OverloadResolutionFailure; originalUserDefinedOperators = default(ImmutableArray); @@ -1180,10 +1180,11 @@ private void ReportObsoleteAndFeatureAvailabilityDiagnostics(MethodSymbol operat } } - private bool IsDefaultLiteralOrNewAllowedInBinaryOperator(BinaryOperatorKind kind, BoundExpression left, BoundExpression right) + private bool IsTypelessExpressionAllowedInBinaryOperator(BinaryOperatorKind kind, BoundExpression left, BoundExpression right) { - // The default literal is only allowed with equality operators - // and both operands cannot be typeless at the same time. + // The default literal is only allowed with equality operators and both operands cannot be typeless at the same time. + // Note: we only need to restrict expressions that can be converted to *any* type, in which case the resolution could always succeed. + if (left.IsTypelessNew()) { return !right.IsLiteralDefaultOrTypelessNew(); From fac36f2769672c2523a591354429a6dc48c4c80c Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 19 Dec 2019 21:14:14 +0330 Subject: [PATCH 15/41] Add suggested tests --- .../TargetTypedObjectCreationTests.cs | 186 +++++++++++++++--- 1 file changed, 163 insertions(+), 23 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs index 7baabd3892a69..019eb9798e228 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs @@ -11,9 +11,11 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Semantics { public class TargetTypedObjectCreationTests : CSharpTestBase { + private static readonly CSharpParseOptions TargetTypedObjectCreationTestOptions = TestOptions.RegularPreview; + private static CSharpCompilation CreateCompilation(string source, CSharpCompilationOptions options = null, IEnumerable references = null) { - return CSharpTestBase.CreateCompilation(source, options: options, parseOptions: TestOptions.RegularPreview, references: references); + return CSharpTestBase.CreateCompilation(source, options: options, parseOptions: TargetTypedObjectCreationTestOptions, references: references); } [Fact] @@ -273,6 +275,28 @@ public static void Main() CompileAndVerify(comp, expectedOutput: "5"); } + [Fact] + public void TestInDynamicInvocation() + { + var source = @" +class C +{ + public void M(int i) {} + + public static void Main() + { + dynamic d = new C(); + d.M(new()); + } +} +"; + var comp = CreateCompilation(source, options: TestOptions.DebugExe, references: new[] { CSharpRef }); + comp.VerifyDiagnostics( + // (9,13): error CS8754: There is no target type for new() + // d.M(new()); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(9, 13)); + } + [Fact] public void TestInAsOperator() { @@ -285,21 +309,32 @@ struct S class C { - public static void Main() + public void M() + where TClass : class + where TNew : new() { Console.Write(new() as C); Console.Write(new() as S?); + Console.Write(new() as TClass); + Console.Write(new() as TNew); } } "; - var comp = CreateCompilation(source, options: TestOptions.DebugExe); + var comp = CreateCompilation(source, options: TestOptions.DebugDll); comp.VerifyDiagnostics( - // (12,23): error CS8754: There is no target type for new() expression - // Console.Write(new() as C); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(12, 23), - // (13,23): error CS8754: There is no target type for new() expression - // Console.Write(new() as S?); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(13, 23)); + // (14,23): error CS8754: There is no target type for new() + // Console.Write(new() as C); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(14, 23), + // (15,23): error CS8754: There is no target type for new() + // Console.Write(new() as S?); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(15, 23), + // (16,23): error CS8754: There is no target type for new() + // Console.Write(new() as TClass); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(16, 23), + // (17,23): error CS8754: There is no target type for new() + // Console.Write(new() as TNew); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(17, 23) + ); } [Fact] @@ -345,6 +380,26 @@ void M() ); } + [Fact] + public void TestTargetType_Discard() + { + var source = @" +class C +{ + void M() + { + _ = new(); + } +} +"; + var comp = CreateCompilation(source); + comp.VerifyDiagnostics( + // (6,13): error CS8754: There is no target type for new() + // _ = new(); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 13) + ); + } + [Fact] public void TestTargetType_Delegate() { @@ -376,7 +431,6 @@ void M() public void TestTargetType_Static() { var source = @" -using System; public static class C { static void M(object c) { _ = (C)(new()); @@ -385,16 +439,13 @@ static void M(object c) { "; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (5,13): error CS0716: Cannot convert to static type 'C' - // _ = (C)(new()); - Diagnostic(ErrorCode.ERR_ConvertToStaticClass, "(C)(new())").WithArguments("C").WithLocation(5, 13), - // (5,17): error CS1729: 'C' does not contain a constructor that takes 0 arguments - // _ = (C)(new()); - Diagnostic(ErrorCode.ERR_BadCtorArgCount, "new()").WithArguments("C", "0").WithLocation(5, 17), - // (2,1): hidden CS8019: Unnecessary using directive. - // using System; - Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using System;").WithLocation(2, 1) - ); + // (4,13): error CS0716: Cannot convert to static type 'C' + // _ = (C)(new()); + Diagnostic(ErrorCode.ERR_ConvertToStaticClass, "(C)(new())").WithArguments("C").WithLocation(4, 13), + // (4,17): error CS1729: 'C' does not contain a constructor that takes 0 arguments + // _ = (C)(new()); + Diagnostic(ErrorCode.ERR_BadCtorArgCount, "new()").WithArguments("C", "0").WithLocation(4, 17) + ); } [Fact] @@ -506,6 +557,8 @@ void M() { (int, int) x0 = new(); var x1 = ((int, int))new(); + (int, C) x2 = new(); + var x3 = ((int, C))new(); } } "; @@ -1235,13 +1288,13 @@ public Dog() {} } public class Animal { - private Animal() {} + MODIFIER Animal() {} public static implicit operator Animal(Dog dog) => throw null; } public class Program { - public static void M(Animal a) => throw null; + public static void M(Animal a) => System.Console.Write(a); public static void Main() { M(new()); @@ -1249,11 +1302,14 @@ public static void Main() } "; - var comp = CreateCompilation(source, options: TestOptions.DebugExe).VerifyDiagnostics( + var comp1 = CreateCompilation(source.Replace("MODIFIER", "private"), options: TestOptions.DebugExe).VerifyDiagnostics( // (17,11): error CS0122: 'Animal.Animal()' is inaccessible due to its protection level // M(new()); Diagnostic(ErrorCode.ERR_BadAccess, "new()").WithArguments("Animal.Animal()").WithLocation(17, 11) ); + var comp2 = CreateCompilation(source.Replace("MODIFIER", "public"), options: TestOptions.DebugExe).VerifyDiagnostics( + ); + CompileAndVerify(comp2, expectedOutput: "Animal"); } [ConditionalFact(typeof(DesktopOnly), Reason = ConditionalSkipReason.RestrictedTypesNeedDesktop)] @@ -1879,6 +1935,23 @@ static void Main() // using (System.IDisposable x = new()) Diagnostic(ErrorCode.ERR_NoNewAbstract, "new()").WithArguments("System.IDisposable").WithLocation(14, 39) ); + + var tree = comp.SyntaxTrees.First(); + var model = comp.GetSemanticModel(tree); + var nodes = tree.GetCompilationUnitRoot().DescendantNodes().OfType().ToArray(); + + assert(0, type: "?", convertedType: "?", ConversionKind.Identity); + assert(1, type: "?", convertedType: "?", ConversionKind.Identity); + assert(2, type: "System.IDisposable", convertedType: "System.IDisposable", ConversionKind.Identity); + + void assert(int index, string type, string convertedType, ConversionKind conversionKind) + { + var @new = nodes[index]; + Assert.Equal(type, model.GetTypeInfo(@new).Type.ToTestDisplayString()); + Assert.Equal(convertedType, model.GetTypeInfo(@new).ConvertedType.ToTestDisplayString()); + Assert.Null(model.GetSymbolInfo(@new).Symbol); + Assert.Equal(conversionKind, model.GetConversion(@new).Kind); + } } [Fact] @@ -2509,6 +2582,27 @@ static void Main() ); } + [Fact] + public void InOutArgument() + { + string source = @" +class C +{ + static void M(out int i) + { + i = 0; + M(out new()); + } +} +"; + var comp = CreateCompilation(source, options: TestOptions.DebugDll); + comp.VerifyDiagnostics( + // (7,15): error CS1510: A ref or out value must be an assignable variable + // M(out new()); + Diagnostic(ErrorCode.ERR_RefLvalueExpected, "new()").WithLocation(7, 15) + ); + } + [Fact] public void InSizeOf() { @@ -2607,6 +2701,52 @@ static void Main() ); } + [Fact] + public void InRange() + { + string source = @" +using System; +class C +{ + static void Main() + { + Range x0 = new()..new(); + Range x1 = 1..new(); + Range x2 = new()..1; + Console.WriteLine($""{x0.Start.Value}..{x0.End.Value}""); + Console.WriteLine($""{x1.Start.Value}..{x1.End.Value}""); + Console.WriteLine($""{x2.Start.Value}..{x2.End.Value}""); + } +} +"; + var comp = CreateCompilationWithIndexAndRange(source, options: TestOptions.DebugExe, parseOptions: TargetTypedObjectCreationTestOptions); + comp.VerifyDiagnostics(); + + var expectedOutput = +@"0..0 +1..0 +0..1"; + CompileAndVerify(comp, expectedOutput: expectedOutput); + + var tree = comp.SyntaxTrees.First(); + var model = comp.GetSemanticModel(tree); + var nodes = tree.GetCompilationUnitRoot().DescendantNodes().OfType().ToArray(); + + assert(0, type: "System.Index", convertedType: "System.Index", symbol: "System.Index..ctor()", ConversionKind.Identity); + assert(1, type: "System.Index", convertedType: "System.Index", symbol: "System.Index..ctor()", ConversionKind.Identity); + assert(2, type: "System.Index", convertedType: "System.Index", symbol: "System.Index..ctor()", ConversionKind.Identity); + assert(3, type: "System.Index", convertedType: "System.Index", symbol: "System.Index..ctor()", ConversionKind.Identity); + + void assert(int index, string type, string convertedType, string symbol, ConversionKind conversionKind) + { + var @new = nodes[index]; + Assert.Equal(type, model.GetTypeInfo(@new).Type.ToTestDisplayString()); + Assert.Equal(convertedType, model.GetTypeInfo(@new).ConvertedType.ToTestDisplayString()); + Assert.Equal(symbol, model.GetSymbolInfo(@new).Symbol.ToTestDisplayString()); + Assert.Equal(conversionKind, model.GetConversion(@new).Kind); + } + } + [Fact] public void RefTypeAndValue() { From c12c38cd300f05de16a271f5d1534329d50de02d Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 19 Dec 2019 21:14:21 +0330 Subject: [PATCH 16/41] Update compiler test plan --- docs/contributing/Compiler Test Plan.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/contributing/Compiler Test Plan.md b/docs/contributing/Compiler Test Plan.md index 38a36dca2b51e..e6521205f5510 100644 --- a/docs/contributing/Compiler Test Plan.md +++ b/docs/contributing/Compiler Test Plan.md @@ -208,6 +208,7 @@ a[e] x++ x-- new X() +new() typeof(T) default(T) default From d6604432497434d71950454266809ce3da809c8e Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 19 Dec 2019 21:34:31 +0330 Subject: [PATCH 17/41] Fix tuple equality --- .../Portable/Binder/Binder_TupleOperators.cs | 22 ++++++++---- .../TargetTypedObjectCreationTests.cs | 34 ++++++++----------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs b/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs index eb185517d371c..3718de30defb7 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs @@ -191,8 +191,8 @@ private TupleBinaryOperatorInfo BindTupleDynamicBinaryOperatorSingleInfo(BinaryE private TupleBinaryOperatorInfo.Multiple BindTupleBinaryOperatorNestedInfo(BinaryExpressionSyntax node, BinaryOperatorKind kind, BoundExpression left, BoundExpression right, DiagnosticBag diagnostics) { - left = GiveTupleTypeToDefaultLiteralIfNeeded(left, right.Type); - right = GiveTupleTypeToDefaultLiteralIfNeeded(right, left.Type); + left = GiveTupleTypeToTypelessExpressionIfNeeded(left, right.Type, diagnostics); + right = GiveTupleTypeToTypelessExpressionIfNeeded(right, left.Type, diagnostics); if ((left.Type is null && left.IsLiteralDefaultOrTypelessNew()) || (right.Type is null && right.IsLiteralDefaultOrTypelessNew())) @@ -311,15 +311,23 @@ private static void ReportNamesMismatchesIfAny(BoundExpression left, BoundExpres } } - internal static BoundExpression GiveTupleTypeToDefaultLiteralIfNeeded(BoundExpression expr, TypeSymbol targetType) + internal BoundExpression GiveTupleTypeToTypelessExpressionIfNeeded(BoundExpression expr, TypeSymbol targetType, DiagnosticBag diagnostics) { - if (!expr.IsLiteralDefault() || targetType is null) + if (targetType is object) { - return expr; + if (expr.IsLiteralDefault()) + { + Debug.Assert(targetType.StrippedType().IsTupleType); + return new BoundDefaultExpression(expr.Syntax, targetType); + } + + if (expr is UnboundObjectCreationExpression objectCreation) + { + return ConvertObjectCreationExpression(objectCreation, false, targetType, diagnostics); + } } - Debug.Assert(targetType.StrippedType().IsTupleType); - return new BoundDefaultExpression(expr.Syntax, targetType); + return expr; } private static bool IsTupleBinaryOperation(BoundExpression left, BoundExpression right) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs index 019eb9798e228..800112ba9a065 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs @@ -3484,32 +3484,26 @@ static System.Func M() public void TestTupleEquality01() { string source = @" +using System; class C { - void M1() + public static void Main() { - var v1 = new() == (1, 2L); - var v2 = new() != (1, 2L); - var v3 = (1, 2L) == new(); - var v4 = (1, 2L) != new(); + Console.Write(new() == (1, 2L) ? 1 : 0); + Console.Write(new() != (1, 2L) ? 1 : 0); + Console.Write((1, 2L) == new() ? 1 : 0); + Console.Write((1, 2L) != new() ? 1 : 0); + Console.Write('-'); + Console.Write(new(1, 2L) == (1, 2L) ? 1 : 0); + Console.Write(new(1, 2L) != (1, 2L) ? 1 : 0); + Console.Write((1, 2L) == new(1, 2L) ? 1 : 0); + Console.Write((1, 2L) != new(1, 2L) ? 1 : 0); } } "; - - var comp = CreateCompilation(source, options: TestOptions.DebugDll); - comp.VerifyDiagnostics( - // (6,18): error CS0034: Operator '==' is ambiguous on operands of type 'new()' and '(int, long)' - // var v1 = new() == (1, 2L); - Diagnostic(ErrorCode.ERR_AmbigBinaryOps, "new() == (1, 2L)").WithArguments("==", "new()", "(int, long)").WithLocation(6, 18), - // (7,18): error CS0034: Operator '!=' is ambiguous on operands of type 'new()' and '(int, long)' - // var v2 = new() != (1, 2L); - Diagnostic(ErrorCode.ERR_AmbigBinaryOps, "new() != (1, 2L)").WithArguments("!=", "new()", "(int, long)").WithLocation(7, 18), - // (8,18): error CS0034: Operator '==' is ambiguous on operands of type '(int, long)' and 'new()' - // var v3 = (1, 2L) == new(); - Diagnostic(ErrorCode.ERR_AmbigBinaryOps, "(1, 2L) == new()").WithArguments("==", "(int, long)", "new()").WithLocation(8, 18), - // (9,18): error CS0034: Operator '!=' is ambiguous on operands of type '(int, long)' and 'new()' - // var v4 = (1, 2L) != new(); - Diagnostic(ErrorCode.ERR_AmbigBinaryOps, "(1, 2L) != new()").WithArguments("!=", "(int, long)", "new()").WithLocation(9, 18)); + var comp = CreateCompilation(source, options: TestOptions.DebugExe); + comp.VerifyDiagnostics(); + CompileAndVerify(comp, expectedOutput: "0101-1010"); } [Fact] From b421d5c6880b8a541674f887ba72298665d09fe7 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 19 Dec 2019 21:56:58 +0330 Subject: [PATCH 18/41] Fix typo --- src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml index 960de4d986689..4304979db24a7 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml @@ -1542,7 +1542,7 @@ From 8fbe7fabd8be9c69e88b26f6885f3a77b3906910 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 24 Dec 2019 21:27:55 +0330 Subject: [PATCH 19/41] Test conditional access --- .../Portable/Binder/Binder_Conversions.cs | 5 +++-- .../TargetTypedObjectCreationTests.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs index 7a06867a67e47..7535ce0cfb072 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs @@ -166,13 +166,14 @@ private BoundExpression ConvertObjectCreationExpression(UnboundObjectCreationExp // if the destination is nullable, in which case we // target the underlying type e.g. `S? x = new();` // is actually identical to `S? x = new S();`. + var conversion = new Conversion(ConversionKind.ImplicitNullable, Conversion.IdentityUnderlying); expr = new BoundConversion( node.Syntax, operand: expr, - conversion: new Conversion(ConversionKind.ImplicitNullable, Conversion.IdentityUnderlying), + conversion: conversion, @checked: false, explicitCastInCode: isCast, - conversionGroupOpt: null, + conversionGroupOpt: new ConversionGroup(conversion), constantValueOpt: expr.ConstantValue, type: destination); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs index 800112ba9a065..f7677519c37c3 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs @@ -859,6 +859,25 @@ public static void Main() ); } + [Fact] + public void TestConditionalAccess() + { + var source = @" +using System; +class C +{ + public static void Main() + { + Console.Write(((int?)new())?.ToString()); + } +} +"; + + var comp = CreateCompilation(source, options: TestOptions.DebugExe); + comp.VerifyDiagnostics(); + CompileAndVerify(comp, expectedOutput: "0"); + } + [Fact] public void TestInaccessibleConstructor() { From 965c50c51f07b11517f9071514b250b6f03a18f0 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 7 Jan 2020 19:48:42 +0330 Subject: [PATCH 20/41] Renamings --- .../Portable/Binder/Binder_Conversions.cs | 6 ++-- .../Portable/Binder/Binder_Expressions.cs | 6 ++-- .../Portable/Binder/Binder_TupleOperators.cs | 4 +-- .../Semantics/Conversions/ConversionsBase.cs | 2 +- .../Portable/BoundTree/BoundExpression.cs | 2 +- .../BoundTree/BoundExpressionExtensions.cs | 2 +- .../CSharp/Portable/BoundTree/BoundNodes.xml | 2 +- .../CSharp/Portable/BoundTree/Formatting.cs | 2 +- .../Portable/FlowAnalysis/AbstractFlowPass.cs | 2 +- .../Portable/FlowAnalysis/NullableWalker.cs | 4 +-- .../Generated/BoundNodes.xml.Generated.cs | 32 +++++++++---------- .../Lowering/LocalRewriter/LocalRewriter.cs | 2 +- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs index 7535ce0cfb072..4f807cf8b0f1f 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs @@ -126,7 +126,7 @@ protected BoundExpression CreateConversion( if (conversion.IsObjectCreation) { - return ConvertObjectCreationExpression((UnboundObjectCreationExpression)source, isCast, destination, diagnostics); + return ConvertObjectCreationExpression((BoundUnconvertedObjectCreationExpression)source, isCast, destination, diagnostics); } if (conversion.IsUserDefined) @@ -156,7 +156,7 @@ protected BoundExpression CreateConversion( { WasCompilerGenerated = wasCompilerGenerated }; } - private BoundExpression ConvertObjectCreationExpression(UnboundObjectCreationExpression node, bool isCast, TypeSymbol destination, DiagnosticBag diagnostics) + private BoundExpression ConvertObjectCreationExpression(BoundUnconvertedObjectCreationExpression node, bool isCast, TypeSymbol destination, DiagnosticBag diagnostics) { var arguments = AnalyzedArguments.GetInstance(node.Arguments, node.ArgumentRefKindsOpt, node.ArgumentNamesOpt); BoundExpression expr = BindObjectCreationExpression(node, destination.StrippedType(), arguments, diagnostics); @@ -181,7 +181,7 @@ private BoundExpression ConvertObjectCreationExpression(UnboundObjectCreationExp return expr; } - private BoundExpression BindObjectCreationExpression(UnboundObjectCreationExpression node, TypeSymbol type, AnalyzedArguments arguments, DiagnosticBag diagnostics) + private BoundExpression BindObjectCreationExpression(BoundUnconvertedObjectCreationExpression node, TypeSymbol type, AnalyzedArguments arguments, DiagnosticBag diagnostics) { var syntax = node.Syntax; switch (type.TypeKind) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 1a57b0741ec4a..854ed4e5378bf 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -301,7 +301,7 @@ internal BoundExpression BindToNaturalType(BoundExpression expression, Diagnosti hasErrors: true).WithSuppression(defaultExpr.IsSuppressed); } break; - case UnboundObjectCreationExpression expr: + case BoundUnconvertedObjectCreationExpression expr: { if (reportNoTargetType) { @@ -3918,7 +3918,7 @@ private BoundExpression BindImplicitObjectCreationExpression(ImplicitObjectCreat { var arguments = AnalyzedArguments.GetInstance(); BindArgumentsAndNames(node.ArgumentList, diagnostics, arguments, allowArglist: true); - var result = new UnboundObjectCreationExpression( + var result = new BoundUnconvertedObjectCreationExpression( node, arguments.Arguments.ToImmutable(), arguments.Names.ToImmutableOrNull(), @@ -4178,7 +4178,7 @@ private BoundExpression BindClassCreationExpression(ObjectCreationExpressionSynt } } - internal BoundExpression BindObjectCreationForErrorRecovery(UnboundObjectCreationExpression node, DiagnosticBag diagnostics) + internal BoundExpression BindObjectCreationForErrorRecovery(BoundUnconvertedObjectCreationExpression node, DiagnosticBag diagnostics) { var arguments = AnalyzedArguments.GetInstance(node.Arguments, node.ArgumentRefKindsOpt, node.ArgumentNamesOpt); var result = MakeBadExpressionForObjectCreation(node.Syntax, CreateErrorType(), arguments, node.InitializerOpt, typeSyntax: node.Syntax, diagnostics); diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs b/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs index 3718de30defb7..a31d3c0816fdd 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs @@ -321,9 +321,9 @@ internal BoundExpression GiveTupleTypeToTypelessExpressionIfNeeded(BoundExpressi return new BoundDefaultExpression(expr.Syntax, targetType); } - if (expr is UnboundObjectCreationExpression objectCreation) + if (expr is BoundUnconvertedObjectCreationExpression objectCreation) { - return ConvertObjectCreationExpression(objectCreation, false, targetType, diagnostics); + return ConvertObjectCreationExpression(objectCreation, isCast: false, targetType, diagnostics); } } diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs index 8c559173a5d08..90a31de27a5a5 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs @@ -923,7 +923,7 @@ private Conversion ClassifyImplicitBuiltInConversionFromExpression(BoundExpressi case BoundKind.ThrowExpression: return Conversion.ImplicitThrow; - case BoundKind.UnboundObjectCreationExpression: + case BoundKind.UnconvertedObjectCreationExpression: return Conversion.ObjectCreation; } diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs index b493e62bcd2b5..96f709c578bd5 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs @@ -54,7 +54,7 @@ internal bool NeedsToBeConverted() { case BoundKind.TupleLiteral: case BoundKind.UnconvertedSwitchExpression: - case BoundKind.UnboundObjectCreationExpression: + case BoundKind.UnconvertedObjectCreationExpression: return true; #if DEBUG case BoundKind.Local when !WasConverted: diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundExpressionExtensions.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundExpressionExtensions.cs index 6af2bee07e821..5abc4599f75ae 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundExpressionExtensions.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundExpressionExtensions.cs @@ -45,7 +45,7 @@ public static bool IsLiteralDefault(this BoundExpression node) public static bool IsTypelessNew(this BoundExpression node) { - return node.Kind == BoundKind.UnboundObjectCreationExpression; + return node.Kind == BoundKind.UnconvertedObjectCreationExpression; } public static bool IsLiteralDefaultOrTypelessNew(this BoundExpression node) diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml index 4304979db24a7..822599e995f19 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml @@ -1545,7 +1545,7 @@ This node is used to represent a target-typed object creation expression It does not survive past initial binding. --> - + diff --git a/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs b/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs index f88158a08f15a..575e57611b583 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs @@ -164,7 +164,7 @@ internal partial class BoundPassByCopy public override object Display => Expression.Display; } - internal partial class UnboundObjectCreationExpression + internal partial class BoundUnconvertedObjectCreationExpression { public override object Display => "new()"; } diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs index e387bc745919a..c5f34f3b56370 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs @@ -2716,7 +2716,7 @@ public override BoundNode VisitDefaultExpression(BoundDefaultExpression node) return null; } - public override BoundNode VisitUnboundObjectCreationExpression(UnboundObjectCreationExpression node) + public override BoundNode VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node) { throw ExceptionUtilities.Unreachable; } diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index 405e015d76ece..66e0bb753396a 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -1811,7 +1811,7 @@ public override BoundNode VisitObjectCreationExpression(BoundObjectCreationExpre return null; } - public override BoundNode VisitUnboundObjectCreationExpression(UnboundObjectCreationExpression node) + public override BoundNode VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node) { var discardedDiagnostics = new DiagnosticBag(); var expr = _binder.BindObjectCreationForErrorRecovery(node, discardedDiagnostics); @@ -4288,7 +4288,7 @@ private static NullableAnnotation GetNullableAnnotation(BoundExpression expr) return ((BoundExpressionWithNullability)expr).NullableAnnotation; case BoundKind.MethodGroup: case BoundKind.UnboundLambda: - case BoundKind.UnboundObjectCreationExpression: + case BoundKind.UnconvertedObjectCreationExpression: return NullableAnnotation.NotAnnotated; default: Debug.Assert(false); // unexpected value diff --git a/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs b/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs index 4750504bc1d7a..209a90636530f 100644 --- a/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs @@ -159,7 +159,7 @@ internal enum BoundKind: byte Call, EventAssignmentOperator, Attribute, - UnboundObjectCreationExpression, + UnconvertedObjectCreationExpression, ObjectCreationExpression, TupleLiteral, ConvertedTupleLiteral, @@ -5478,10 +5478,10 @@ public BoundAttribute Update(MethodSymbol? constructor, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, InitializerExpressionSyntax? initializerOpt, bool hasErrors = false) - : base(BoundKind.UnboundObjectCreationExpression, syntax, null, hasErrors || arguments.HasErrors()) + public BoundUnconvertedObjectCreationExpression(SyntaxNode syntax, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, InitializerExpressionSyntax? initializerOpt, bool hasErrors = false) + : base(BoundKind.UnconvertedObjectCreationExpression, syntax, null, hasErrors || arguments.HasErrors()) { Debug.Assert(!arguments.IsDefault, "Field 'arguments' cannot be null (use Null=\"allow\" in BoundNodes.xml to remove this check)"); @@ -5503,13 +5503,13 @@ public UnboundObjectCreationExpression(SyntaxNode syntax, ImmutableArray visitor.VisitUnboundObjectCreationExpression(this); + public override BoundNode? Accept(BoundTreeVisitor visitor) => visitor.VisitUnconvertedObjectCreationExpression(this); - public UnboundObjectCreationExpression Update(ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, InitializerExpressionSyntax? initializerOpt) + public BoundUnconvertedObjectCreationExpression Update(ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, InitializerExpressionSyntax? initializerOpt) { if (arguments != this.Arguments || argumentNamesOpt != this.ArgumentNamesOpt || argumentRefKindsOpt != this.ArgumentRefKindsOpt || initializerOpt != this.InitializerOpt) { - var result = new UnboundObjectCreationExpression(this.Syntax, arguments, argumentNamesOpt, argumentRefKindsOpt, initializerOpt, this.HasErrors); + var result = new BoundUnconvertedObjectCreationExpression(this.Syntax, arguments, argumentNamesOpt, argumentRefKindsOpt, initializerOpt, this.HasErrors); result.CopyAttributes(this); return result; } @@ -7710,8 +7710,8 @@ internal R VisitInternal(BoundNode node, A arg) return VisitEventAssignmentOperator((BoundEventAssignmentOperator)node, arg); case BoundKind.Attribute: return VisitAttribute((BoundAttribute)node, arg); - case BoundKind.UnboundObjectCreationExpression: - return VisitUnboundObjectCreationExpression((UnboundObjectCreationExpression)node, arg); + case BoundKind.UnconvertedObjectCreationExpression: + return VisitUnconvertedObjectCreationExpression((BoundUnconvertedObjectCreationExpression)node, arg); case BoundKind.ObjectCreationExpression: return VisitObjectCreationExpression((BoundObjectCreationExpression)node, arg); case BoundKind.TupleLiteral: @@ -7956,7 +7956,7 @@ internal abstract partial class BoundTreeVisitor public virtual R VisitCall(BoundCall node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitEventAssignmentOperator(BoundEventAssignmentOperator node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitAttribute(BoundAttribute node, A arg) => this.DefaultVisit(node, arg); - public virtual R VisitUnboundObjectCreationExpression(UnboundObjectCreationExpression node, A arg) => this.DefaultVisit(node, arg); + public virtual R VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitObjectCreationExpression(BoundObjectCreationExpression node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitTupleLiteral(BoundTupleLiteral node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitConvertedTupleLiteral(BoundConvertedTupleLiteral node, A arg) => this.DefaultVisit(node, arg); @@ -8148,7 +8148,7 @@ internal abstract partial class BoundTreeVisitor public virtual BoundNode? VisitCall(BoundCall node) => this.DefaultVisit(node); public virtual BoundNode? VisitEventAssignmentOperator(BoundEventAssignmentOperator node) => this.DefaultVisit(node); public virtual BoundNode? VisitAttribute(BoundAttribute node) => this.DefaultVisit(node); - public virtual BoundNode? VisitUnboundObjectCreationExpression(UnboundObjectCreationExpression node) => this.DefaultVisit(node); + public virtual BoundNode? VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node) => this.DefaultVisit(node); public virtual BoundNode? VisitObjectCreationExpression(BoundObjectCreationExpression node) => this.DefaultVisit(node); public virtual BoundNode? VisitTupleLiteral(BoundTupleLiteral node) => this.DefaultVisit(node); public virtual BoundNode? VisitConvertedTupleLiteral(BoundConvertedTupleLiteral node) => this.DefaultVisit(node); @@ -8816,7 +8816,7 @@ internal abstract partial class BoundTreeWalker: BoundTreeVisitor this.VisitList(node.NamedArguments); return null; } - public override BoundNode? VisitUnboundObjectCreationExpression(UnboundObjectCreationExpression node) + public override BoundNode? VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node) { this.VisitList(node.Arguments); return null; @@ -9850,7 +9850,7 @@ internal abstract partial class BoundTreeRewriter : BoundTreeVisitor TypeSymbol type = this.VisitType(node.Type); return node.Update(node.Constructor, constructorArguments, node.ConstructorArgumentNamesOpt, node.ConstructorArgumentsToParamsOpt, node.ConstructorExpanded, namedArguments, node.ResultKind, type); } - public override BoundNode? VisitUnboundObjectCreationExpression(UnboundObjectCreationExpression node) + public override BoundNode? VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node) { ImmutableArray arguments = this.VisitList(node.Arguments); TypeSymbol type = this.VisitType(node.Type); @@ -11637,10 +11637,10 @@ public NullabilityRewriter(ImmutableDictionary arguments = this.VisitList(node.Arguments); - UnboundObjectCreationExpression updatedNode; + BoundUnconvertedObjectCreationExpression updatedNode; if (_updatedNullabilities.TryGetValue(node, out (NullabilityInfo Info, TypeSymbol Type) infoAndType)) { @@ -13648,7 +13648,7 @@ private BoundTreeDumperNodeProducer() new TreeDumperNode("hasErrors", node.HasErrors, null) } ); - public override TreeDumperNode VisitUnboundObjectCreationExpression(UnboundObjectCreationExpression node, object? arg) => new TreeDumperNode("unboundObjectCreationExpression", null, new TreeDumperNode[] + public override TreeDumperNode VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node, object? arg) => new TreeDumperNode("unconvertedObjectCreationExpression", null, new TreeDumperNode[] { new TreeDumperNode("arguments", null, from x in node.Arguments select Visit(x, null)), new TreeDumperNode("argumentNamesOpt", node.ArgumentNamesOpt, null), diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs index 02efa0c55ecce..d7dfc945b3794 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs @@ -292,7 +292,7 @@ public override BoundNode VisitDefaultLiteral(BoundDefaultLiteral node) throw ExceptionUtilities.Unreachable; } - public override BoundNode VisitUnboundObjectCreationExpression(UnboundObjectCreationExpression node) + public override BoundNode VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node) { throw ExceptionUtilities.Unreachable; } From cff10ef366402bbf1a7e5711195547f19300798c Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 7 Jan 2020 20:07:39 +0330 Subject: [PATCH 21/41] Fixup merge --- src/Compilers/CSharp/Portable/Parser/LanguageParser.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 1e705928f60ed..2fa4899385c8f 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -8793,6 +8793,7 @@ private static Precedence GetPrecedence(SyntaxKind op) case SyntaxKind.IdentifierName: case SyntaxKind.ImplicitArrayCreationExpression: case SyntaxKind.ImplicitStackAllocArrayCreationExpression: + case SyntaxKind.ImplicitObjectCreationExpression: case SyntaxKind.InterpolatedStringExpression: case SyntaxKind.InvocationExpression: case SyntaxKind.NullLiteralExpression: From 471dfce5c0557affccbcb7b334e6297b1d93702c Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 9 Jan 2020 16:49:04 +0330 Subject: [PATCH 22/41] Fixup tests --- .../CSharp/Portable/Parser/LanguageParser.cs | 1 + .../IOperationTests_IConversionExpression.cs | 3 -- .../Test/Syntax/Parsing/RefReadonlyTests.cs | 3 ++ .../Test/Syntax/Parsing/ScriptParsingTests.cs | 26 ++++++++++++++ .../TargetTypedObjectCreationParsingTests.cs | 34 +++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 2fa4899385c8f..e988eb462400a 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -6011,6 +6011,7 @@ bool canBeNullableType() case ParseTypeMode.Normal: case ParseTypeMode.Parameter: case ParseTypeMode.AfterOut: + case ParseTypeMode.AfterRef: case ParseTypeMode.AsExpression: case ParseTypeMode.NewExpression: type = this.ParsePointerTypeMods(type); diff --git a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IConversionExpression.cs b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IConversionExpression.cs index 4a5b40b1dbb11..38ec1fe02f4bb 100644 --- a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IConversionExpression.cs +++ b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IConversionExpression.cs @@ -945,9 +945,6 @@ static void Main(string[] args) Children(0) "; var expectedDiagnostics = new DiagnosticDescription[] { - // CS1031: Type expected - // C1 /**/c1 = new/**/; - Diagnostic(ErrorCode.ERR_TypeExpected, ";").WithLocation(8, 41), // CS1526: A new expression requires (), [], or {} after type // C1 /**/c1 = new/**/; Diagnostic(ErrorCode.ERR_BadNewExpr, ";").WithLocation(8, 41) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/RefReadonlyTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/RefReadonlyTests.cs index 140d440cfb930..85470d352bce8 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/RefReadonlyTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/RefReadonlyTests.cs @@ -490,6 +490,9 @@ class Test public void TestNewRefArray() { UsingStatement("new ref[];", + // (1,8): error CS1031: Type expected + // new ref[]; + Diagnostic(ErrorCode.ERR_TypeExpected, "[").WithLocation(1, 8), // (1,10): error CS1526: A new expression requires an argument list or (), [], or {} after type // new ref[]; Diagnostic(ErrorCode.ERR_BadNewExpr, ";").WithLocation(1, 10) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/ScriptParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/ScriptParsingTests.cs index cccd5f8aa41c4..e65038ef11699 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/ScriptParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/ScriptParsingTests.cs @@ -93,6 +93,32 @@ public void Error_NewKeywordUsedAsOperator() // (2,5): error CS7017: Member definition, statement, or end-of-file expected // new in Diagnostic(ErrorCode.ERR_GlobalDefinitionOrStatementExpected, "in").WithLocation(2, 5)); + + N(SyntaxKind.CompilationUnit); + { + N(SyntaxKind.GlobalStatement); + { + N(SyntaxKind.ExpressionStatement); + { + N(SyntaxKind.ObjectCreationExpression); + { + N(SyntaxKind.NewKeyword); + M(SyntaxKind.IdentifierName); + { + M(SyntaxKind.IdentifierToken); + } + M(SyntaxKind.ArgumentList); + { + M(SyntaxKind.OpenParenToken); + M(SyntaxKind.CloseParenToken); + } + } + M(SyntaxKind.SemicolonToken); + } + } + N(SyntaxKind.EndOfFileToken); + } + EOF(); } #region Method Declarations diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs index 45b10c43b2d1d..e977b862f983b 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs @@ -308,6 +308,40 @@ public void TestBinaryOperators(SyntaxKind expressionKind, SyntaxKind tokenKind) // new(Int32,Int32) + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(1, 19)); + N(expressionKind); + { + N(SyntaxKind.ImplicitObjectCreationExpression); + { + N(SyntaxKind.NewKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "Int32"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "Int32"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(tokenKind); + M(SyntaxKind.IdentifierName); + { + M(SyntaxKind.IdentifierToken); + } + } + EOF(); + UsingExpression($"new(Int32,Int32){SyntaxFacts.GetText(tokenKind),2}e", DefaultParseOptions); N(expressionKind); From a1fc531e58980811164d22215a2243c23b34582d Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Wed, 29 Jan 2020 16:08:02 +0330 Subject: [PATCH 23/41] Update resources --- .../Portable/xlf/CSharpResources.cs.xlf | 44 ++++++++++++++----- .../Portable/xlf/CSharpResources.de.xlf | 44 ++++++++++++++----- .../Portable/xlf/CSharpResources.es.xlf | 44 ++++++++++++++----- .../Portable/xlf/CSharpResources.fr.xlf | 44 ++++++++++++++----- .../Portable/xlf/CSharpResources.it.xlf | 44 ++++++++++++++----- .../Portable/xlf/CSharpResources.pl.xlf | 44 ++++++++++++++----- .../Portable/xlf/CSharpResources.tr.xlf | 44 ++++++++++++++----- .../Portable/xlf/CSharpResources.zh-Hans.xlf | 44 ++++++++++++++----- .../Portable/xlf/CSharpResources.zh-Hant.xlf | 44 ++++++++++++++----- 9 files changed, 288 insertions(+), 108 deletions(-) diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index d7f23cb33adbf..b2faab6badc8d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -22,6 +22,11 @@ Pokud chcete pro interpolovaný doslovný řetězec použít @$ místo $@, použijte verzi jazyka {0} nebo vyšší. + + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + + Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type Operátor {0} nejde použít pro default a operand typu {1}, protože se jedná o parametr typu, který není znám jako odkazový typ. @@ -82,6 +87,11 @@ Operátor typeof nejde použít na typ odkazů s možnou hodnotou null. + + Operator '{0}' cannot be applied to operand '{1}' + Operator '{0}' cannot be applied to operand '{1}' + + Invalid operand for pattern match; value required, but found '{0}'. Neplatný operand pro porovnávací vzorek. Vyžaduje se hodnota, ale nalezeno: {0}. @@ -467,6 +477,21 @@ Typy řazené kolekce členů, které se používají jako operandy operátoru == nebo !=, musí mít odpovídající kardinality. U tohoto operátoru je ale kardinalita typů řazené kolekce členů vlevo {0} a vpravo {1}. + + The type '{0}' may not be used as the target type of new() + The type '{0}' may not be used as the target type of new() + + + + There is no target type for new() + There is no target type for new() + + + + Use of new() is not valid in this context + Use of new() is not valid in this context + + '{0}': cannot specify both a constraint class and the 'unmanaged' constraint {0}: Nejde zadat třídu omezení a zároveň omezení unmanaged. @@ -952,6 +977,11 @@ <výraz přepínače> + + target-typed object creation + target-typed object creation + + tuple equality rovnost řazené kolekce členů @@ -2022,11 +2052,6 @@ Operátor {0} nejde použít na operand typu {1}. - - Operator '{0}' cannot be applied to operand '{1}' - Operátor {0} nejde použít pro operand {1}. - - Keyword 'this' is not valid in a static property, static method, or static field initializer Klíčové slovo this není platné ve statické vlastnosti, ve statické metodě ani ve statickém inicializátoru pole. @@ -2067,11 +2092,6 @@ Operátor {0} je nejednoznačný na operandech typu {1} a {2}. - - Operator '{0}' is ambiguous on operands 'default' and 'default' - Operátor {0} je nejednoznačný při použití s operandy default a default. - - Operator '{0}' is ambiguous on an operand of type '{1}' Operátor {0} je nejednoznačný na operandu typu {1}. @@ -5396,8 +5416,8 @@ Blok catch() po bloku catch (System.Exception e) může zachytit výjimky, kter - A new expression requires (), [], or {} after type - Výraz new vyžaduje za typem použití znaků (), [] nebo {} + A new expression requires an argument list or (), [], or {} after type + Výraz new vyžaduje za typem použití znaků (), [] nebo {} diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 9dd59bbbc11d2..3ce66998c786e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -22,6 +22,11 @@ Um für eine interpolierte ausführliche Zeichenfolge "@$" anstelle von "$@" zu verwenden, benötigen Sie Sprachversion {0} oder höher. + + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + + Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type Der Operator "{0}" kann nicht auf "default" und den Operanden vom Typ "{1}" angewendet werden, weil es sich um einen Typparameter handelt, der nicht als Verweistyp bekannt ist. @@ -82,6 +87,11 @@ Der typeof-Operator kann nicht für einen Verweistyp verwendet werden, der NULL-Werte zulässt. + + Operator '{0}' cannot be applied to operand '{1}' + Operator '{0}' cannot be applied to operand '{1}' + + Invalid operand for pattern match; value required, but found '{0}'. Ungültiger Operand für die Musterübereinstimmung. Ein Wert ist erforderlich, gefunden wurde aber "{0}". @@ -467,6 +477,21 @@ Tupeltypen, die als Operanden eines ==- oder !=-Operators verwendet werden, müssen übereinstimmende Kardinalitäten aufweisen. Dieser Operator enthält jedoch Tupeltypen der Kardinalität "{0}" auf der linken und "{1}" auf der rechten Seite. + + The type '{0}' may not be used as the target type of new() + The type '{0}' may not be used as the target type of new() + + + + There is no target type for new() + There is no target type for new() + + + + Use of new() is not valid in this context + Use of new() is not valid in this context + + '{0}': cannot specify both a constraint class and the 'unmanaged' constraint "{0}": Eine Einschränkungsklasse kann nicht gleichzeitig mit einer unmanaged-Einschränkung angegeben werden. @@ -952,6 +977,11 @@ <switch-Ausdruck> + + target-typed object creation + target-typed object creation + + tuple equality Tupelgleichheit @@ -2022,11 +2052,6 @@ Der {0}-Operator kann nicht auf einen Operanden vom Typ "{1}" angewendet werden. - - Operator '{0}' cannot be applied to operand '{1}' - Der Operator "{0}" kann nicht auf den Operanden "{1}" angewendet werden. - - Keyword 'this' is not valid in a static property, static method, or static field initializer Das this-Schlüsselwort ist in einer statischen Eigenschaft/Methode oder einem statischen Feldinitialisierer nicht gültig. @@ -2067,11 +2092,6 @@ Der {0}-Operator ist bei Operanden vom Typ "{1}" und "{2}" mehrdeutig. - - Operator '{0}' is ambiguous on operands 'default' and 'default' - Der Operator "{0}" ist mehrdeutig bei den Operanden "default" und "default". - - Operator '{0}' is ambiguous on an operand of type '{1}' Der {0}-Operator ist für einen Operanden vom Typ "{1}" mehrdeutig. @@ -5396,8 +5416,8 @@ Ein catch()-Block nach einem catch (System.Exception e)-Block kann nicht-CLS-Aus - A new expression requires (), [], or {} after type - Für einen new-Ausdruck ist nach type (), [] oder {} erforderlich. + A new expression requires an argument list or (), [], or {} after type + Für einen new-Ausdruck ist nach type (), [] oder {} erforderlich. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index da6101f0f00b1..db374c4676375 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -22,6 +22,11 @@ Para usar "@$" en lugar de "$@" para una cadena textual interpolada, use la versión "{0}" del lenguaje o una posterior. + + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + + Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type @@ -82,6 +87,11 @@ El operador typeof no se puede usar en un tipo de referencia que acepta valores NULL + + Operator '{0}' cannot be applied to operand '{1}' + Operator '{0}' cannot be applied to operand '{1}' + + Invalid operand for pattern match; value required, but found '{0}'. Operando no válido para la coincidencia de patrones. Se requería un valor, pero se encontró '{0}'. @@ -467,6 +477,21 @@ Los tipos de tupla utilizados como operandos de un operador == o != deben tener cardinalidades coincidentes. Pero este operador tiene tipos de tupla de cardinalidad {0} a la izquierda y {1} a la derecha. + + The type '{0}' may not be used as the target type of new() + The type '{0}' may not be used as the target type of new() + + + + There is no target type for new() + There is no target type for new() + + + + Use of new() is not valid in this context + Use of new() is not valid in this context + + '{0}': cannot specify both a constraint class and the 'unmanaged' constraint "{0}": no se puede especificar a la vez una clase de restricción y la restricción "unmanaged" @@ -952,6 +977,11 @@ <expresión switch> + + target-typed object creation + target-typed object creation + + tuple equality igualdad de tupla @@ -2022,11 +2052,6 @@ El operador '{0}' no se puede aplicar al operando del tipo '{1}' - - Operator '{0}' cannot be applied to operand '{1}' - El operador "{0}" no se puede aplicar al operando del tipo "{1}" - - Keyword 'this' is not valid in a static property, static method, or static field initializer La palabra clave 'this' no es válida en una propiedad, método o inicializador de campo estáticos @@ -2067,11 +2092,6 @@ El operador '{0}' es ambiguo en operandos del tipo '{1}' y '{2}' - - Operator '{0}' is ambiguous on operands 'default' and 'default' - El operador "{0}" es ambiguo en los operandos "default" y "default" - - Operator '{0}' is ambiguous on an operand of type '{1}' El operador '{0}' es ambiguo en un operando del tipo '{1}' @@ -5396,8 +5416,8 @@ Un bloque catch() después de un bloque catch (System.Exception e) puede abarcar - A new expression requires (), [], or {} after type - Una expresión new requiere (), [] o {} después del tipo + A new expression requires an argument list or (), [], or {} after type + Una expresión new requiere (), [] o {} después del tipo diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index f2c2d93af30b0..4e02b792093a6 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -22,6 +22,11 @@ Pour utiliser '@$' à la place de '$@' pour une chaîne verbatim interpolée, utilisez la version de langage '{0}' ou une version ultérieure. + + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + + Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type L'opérateur '{0}' ne peut pas être appliqué à 'default' et à l'opérande de type '{1}', car il s'agit d'un paramètre de type qui n'est pas connu en tant que type référence @@ -82,6 +87,11 @@ Impossible d'utiliser l'opérateur typeof sur un type référence Nullable + + Operator '{0}' cannot be applied to operand '{1}' + Operator '{0}' cannot be applied to operand '{1}' + + Invalid operand for pattern match; value required, but found '{0}'. Opérande non valide pour les critères spéciaux ; la valeur nécessaire n'est pas celle trouvée, '{0}'. @@ -467,6 +477,21 @@ Les types de tuple utilisés en tant qu'opérandes d'un opérateur == ou != doivent avoir des cardinalités correspondantes. Toutefois, cet opérateur a des types de tuple de cardinalité {0} à gauche et {1} à droite. + + The type '{0}' may not be used as the target type of new() + The type '{0}' may not be used as the target type of new() + + + + There is no target type for new() + There is no target type for new() + + + + Use of new() is not valid in this context + Use of new() is not valid in this context + + '{0}': cannot specify both a constraint class and the 'unmanaged' constraint '{0}' : impossible de spécifier à la fois une classe de contrainte et la contrainte 'unmanaged' @@ -952,6 +977,11 @@ <expression switch> + + target-typed object creation + target-typed object creation + + tuple equality égalité de tuple @@ -2022,11 +2052,6 @@ Impossible d'appliquer l'opérateur '{0}' à un opérande de type '{1}' - - Operator '{0}' cannot be applied to operand '{1}' - Impossible d'appliquer l'opérateur '{0}' à un opérande '{1}' - - Keyword 'this' is not valid in a static property, static method, or static field initializer Le mot clé 'this' n'est pas valide dans un initialiseur de propriété statique, de méthode statique ou de champ statique @@ -2067,11 +2092,6 @@ L'opérateur '{0}' est ambigu pour des opérandes de type '{1}' et '{2}' - - Operator '{0}' is ambiguous on operands 'default' and 'default' - L'opérateur '{0}' est ambigu sur les opérandes 'default' et 'default' - - Operator '{0}' is ambiguous on an operand of type '{1}' L'opérateur '{0}' est ambigu pour un opérande de type '{1}' @@ -5396,8 +5416,8 @@ Un bloc catch() après un bloc catch (System.Exception e) peut intercepter des e - A new expression requires (), [], or {} after type - Une expression new exige que type soit suivi de (), [] ou {} + A new expression requires an argument list or (), [], or {} after type + Une expression new exige que type soit suivi de (), [] ou {} diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 8755a61e0f7b4..9164df9c088ab 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -22,6 +22,11 @@ Per usare '@$' invece di '$@' per una stringa verbatim interpolata, usare la versione '{0}' o versioni successive del linguaggio. + + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + + Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type Non è possibile applicare l'operatore '{0}' a 'default ' e all'operando di tipo '{1}' perché è un parametro di tipo non noto come tipo riferimento @@ -82,6 +87,11 @@ Non è possibile usare l'operatore typeof nel tipo riferimento nullable + + Operator '{0}' cannot be applied to operand '{1}' + Operator '{0}' cannot be applied to operand '{1}' + + Invalid operand for pattern match; value required, but found '{0}'. L'operando non è valido per i criteri di ricerca. È richiesto un valore ma è stato trovato '{0}'. @@ -467,6 +477,21 @@ Le cardinalità dei tipi di tupla usati come operandi di un operatore == o != devono essere uguali, ma questo operatore presenta tipi di tupla con cardinalità {0} sulla sinistra e {1} sulla destra. + + The type '{0}' may not be used as the target type of new() + The type '{0}' may not be used as the target type of new() + + + + There is no target type for new() + There is no target type for new() + + + + Use of new() is not valid in this context + Use of new() is not valid in this context + + '{0}': cannot specify both a constraint class and the 'unmanaged' constraint '{0}': non è possibile specificare sia una classe constraint che il vincolo 'unmanaged' @@ -952,6 +977,11 @@ <espressione switch> + + target-typed object creation + target-typed object creation + + tuple equality uguaglianza tuple @@ -2022,11 +2052,6 @@ Non è possibile applicare l'operatore '{0}' all'operando di tipo '{1}' - - Operator '{0}' cannot be applied to operand '{1}' - Non è possibile applicare l'operatore '{0}' all'operando '{1}' - - Keyword 'this' is not valid in a static property, static method, or static field initializer La parola chiave 'this' non può essere utilizzata in una proprietà statica, in un metodo statico o nell'inizializzatore di un campo statico @@ -2067,11 +2092,6 @@ L'operatore '{0}' è ambiguo su operandi di tipo '{1}' e '{2}'. - - Operator '{0}' is ambiguous on operands 'default' and 'default' - L'operatore '{0}' è ambiguo sugli operandi 'default' e 'default' - - Operator '{0}' is ambiguous on an operand of type '{1}' L'operatore '{0}' è ambiguo su un operando di tipo '{1}' @@ -5396,8 +5416,8 @@ Un blocco catch() dopo un blocco catch (System.Exception e) può rilevare eccezi - A new expression requires (), [], or {} after type - Un'espressione new richiede (), [] o {} dopo il tipo + A new expression requires an argument list or (), [], or {} after type + Un'espressione new richiede (), [] o {} dopo il tipo diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index cc4797444f12e..eb0736fc0e801 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -22,6 +22,11 @@ Aby użyć elementu „@$” zamiast elementu „$@” w interpolowanym ciągu dosłownym, użyj wersji języka „{0}” lub nowszej. + + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + + Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type Nie można zastosować operatora „{0}” do elementu „default” i operandu typu „{1}”, ponieważ jest to parametr typu, który nie jest znany jako typ referencyjny @@ -82,6 +87,11 @@ Nie można użyć operatora typeof w przypadku typu referencyjnego dopuszczającego wartość null + + Operator '{0}' cannot be applied to operand '{1}' + Operator '{0}' cannot be applied to operand '{1}' + + Invalid operand for pattern match; value required, but found '{0}'. Nieprawidłowy operand dla dopasowania wzorca; wymagana jest wartość, a znaleziono „{0}”. @@ -467,6 +477,21 @@ Typy krotek używane jako operandy operatorów == lub != muszą mieć zgodne kardynalności. Ten operator zawiera natomiast typy krotek o kardynalności {0} z lewej strony i {1} z prawej strony. + + The type '{0}' may not be used as the target type of new() + The type '{0}' may not be used as the target type of new() + + + + There is no target type for new() + There is no target type for new() + + + + Use of new() is not valid in this context + Use of new() is not valid in this context + + '{0}': cannot specify both a constraint class and the 'unmanaged' constraint „{0}”: nie można jednocześnie określić klasy ograniczenia i ograniczenia „unmanaged” @@ -952,6 +977,11 @@ <wyrażenie przełącznika> + + target-typed object creation + target-typed object creation + + tuple equality równość krotki @@ -2022,11 +2052,6 @@ Nie można zastosować operatora „{0}” do argumentu operacji typu „{1}”. - - Operator '{0}' cannot be applied to operand '{1}' - Nie można zastosować operatora „{0}” do operandu „{1}” - - Keyword 'this' is not valid in a static property, static method, or static field initializer W przypadku statycznej właściwości, statycznej metody lub statycznego inicjatora pola użycie słowa kluczowego „this” jest nieprawidłowe @@ -2067,11 +2092,6 @@ Operator „{0}” jest niejednoznaczny dla operandów typu „{1}” i „{2}” - - Operator '{0}' is ambiguous on operands 'default' and 'default' - Operator „{0}” jest niejednoznaczny dla operandów „default” i „default” - - Operator '{0}' is ambiguous on an operand of type '{1}' Dla argumentu operacji typu „{0}” operator „{1}” jest niejednoznaczny. @@ -5396,8 +5416,8 @@ Blok catch() po bloku catch (System.Exception e) może przechwytywać wyjątki n - A new expression requires (), [], or {} after type - Wyrażenie new wymaga znaków (), [] lub {} po typie. + A new expression requires an argument list or (), [], or {} after type + Wyrażenie new wymaga znaków (), [] lub {} po typie. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index c383ddb1ce56d..a79328468e2df 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -22,6 +22,11 @@ İlişkilendirilmiş tam bir dize için '$@' yerine '@$' kullanmak amacıyla lütfen '{0}' veya daha yüksek bir dil sürümü kullanın. + + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + + Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type '{0}' işleci, başvuru türü olduğu bilinmeyen bir tür parametresi olduğundan 'default' öğesine ve '{1}' türünde işlenene uygulanamıyor @@ -82,6 +87,11 @@ Boş değer atanabilir tür üzerinde typeof işleci kullanılamaz + + Operator '{0}' cannot be applied to operand '{1}' + Operator '{0}' cannot be applied to operand '{1}' + + Invalid operand for pattern match; value required, but found '{0}'. Desen eşleşmesi için işlenen geçersiz. Değer gerekiyordu ancak '{0}' bulundu. @@ -467,6 +477,21 @@ == veya != işlecinin işleneni olarak kullanılan demet türlerinin kardinalitesi eşleşmelidir. Ancak bu işleç, solda {0} ve sağda {1} demet kardinalite türlerine sahip olmalıdır. + + The type '{0}' may not be used as the target type of new() + The type '{0}' may not be used as the target type of new() + + + + There is no target type for new() + There is no target type for new() + + + + Use of new() is not valid in this context + Use of new() is not valid in this context + + '{0}': cannot specify both a constraint class and the 'unmanaged' constraint '{0}': hem bir kısıtlama sınıfı hem de 'unmanaged' kısıtlaması belirtilemez @@ -952,6 +977,11 @@ <switch expression> + + target-typed object creation + target-typed object creation + + tuple equality demet eşitliği @@ -2022,11 +2052,6 @@ {0}' işleci '{1}' türündeki işlenene uygulanamaz - - Operator '{0}' cannot be applied to operand '{1}' - {0}' işleci '{1}' türündeki işlenene uygulanamaz - - Keyword 'this' is not valid in a static property, static method, or static field initializer this' anahtar sözcüğü statik özellikte, statik yöntemde veya statik alan başlatıcısında geçerli değildir @@ -2067,11 +2092,6 @@ {0}' işleci, '{1}' ve '{2}' türündeki işlenenler üzerinde belirsizdir - - Operator '{0}' is ambiguous on operands 'default' and 'default' - {0}' işleci 'default' ve 'default' işlenenlerinde belirsiz - - Operator '{0}' is ambiguous on an operand of type '{1}' {0}' işleci, '{1}' türündeki bir işlenen üzerinde belirsizdir @@ -5396,8 +5416,8 @@ RuntimeCompatibilityAttribute AssemblyInfo.cs dosyasında false olarak ayarlanm - A new expression requires (), [], or {} after type - Bir new ifadesinde türden sonra (), [] veya {} gerekir + A new expression requires an argument list or (), [], or {} after type + Bir new ifadesinde türden sonra (), [] veya {} gerekir diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 98547adf45a75..2c414339a12d1 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -22,6 +22,11 @@ 若要对内插逐字字符串使用 "@$" 而不是 "$@",请使用语言版本 {0} 或更高版本。 + + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + + Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type 运算符“{0}”不能应用于“默认值”和类型为“{1}”的操作数,因为它是一个类型参数,而系统不知道该参数是引用类型 @@ -82,6 +87,11 @@ 不能在可为 null 的引用类型上使用 typeof 运算符 + + Operator '{0}' cannot be applied to operand '{1}' + Operator '{0}' cannot be applied to operand '{1}' + + Invalid operand for pattern match; value required, but found '{0}'. 用于模式匹配的操作数无效;需要值,但找到的是“{0}”。 @@ -467,6 +477,21 @@ 用作 == 或 != 运算符的操作数的元组类型必须具有匹配的基数。但此运算符的基数的元组类型左侧为 {0},右侧为 {1}。 + + The type '{0}' may not be used as the target type of new() + The type '{0}' may not be used as the target type of new() + + + + There is no target type for new() + There is no target type for new() + + + + Use of new() is not valid in this context + Use of new() is not valid in this context + + '{0}': cannot specify both a constraint class and the 'unmanaged' constraint “{0}”: 不能既指定约束类又指定 “unmanaged” 约束 @@ -952,6 +977,11 @@ <switch expression> + + target-typed object creation + target-typed object creation + + tuple equality 元组相等 @@ -2022,11 +2052,6 @@ 运算符“{0}”无法应用于“{1}”类型的操作数 - - Operator '{0}' cannot be applied to operand '{1}' - 运算符“{0}”无法应用于操作数“{1}” - - Keyword 'this' is not valid in a static property, static method, or static field initializer 关键字 "this" 在静态属性、静态方法或静态字段初始值设定项中无效 @@ -2067,11 +2092,6 @@ 运算符“{0}”对于“{1}”和“{2}”类型的操作数具有二义性 - - Operator '{0}' is ambiguous on operands 'default' and 'default' - 运算符“{0}”在操作数 "default" 和 "default" 上不明确 - - Operator '{0}' is ambiguous on an operand of type '{1}' 运算符“{0}”对于“{1}”类型的操作数具有二义性 @@ -5396,8 +5416,8 @@ A catch() block after a catch (System.Exception e) block can catch non-CLS excep - A new expression requires (), [], or {} after type - new 表达式要求在类型后有 ()、[] 或 {} + A new expression requires an argument list or (), [], or {} after type + new 表达式要求在类型后有 ()、[] 或 {} diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 52d032637a0b8..f62248c3042d8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -22,6 +22,11 @@ 若要在插入的逐字字串使用 '@$' 而不是 '$@',請使用 '{0}' 或更高的語言版本。 + + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + Operator '{0}' is ambiguous on operands '{1}' and '{2}' + + Operator '{0}' cannot be applied to 'default' and operand of type '{1}' because it is a type parameter that is not known to be a reference type 無法將運算子 '{0}' 套用至 'default' 和類型為 '{1}' 的運算元,原因是其為未知參考型別的型別參數 @@ -82,6 +87,11 @@ typeof 運算子不得用於可為 Null 的參考型別上 + + Operator '{0}' cannot be applied to operand '{1}' + Operator '{0}' cannot be applied to operand '{1}' + + Invalid operand for pattern match; value required, but found '{0}'. 模式比對運算元無效; 需要值,但找到 '{0}'。 @@ -467,6 +477,21 @@ 作為 == 或 != 運算子之運算元使用的元組類型,必須具有相符的基數。但此運算子在左側的元組類型為基數 {0},在右側則為 {1}。 + + The type '{0}' may not be used as the target type of new() + The type '{0}' may not be used as the target type of new() + + + + There is no target type for new() + There is no target type for new() + + + + Use of new() is not valid in this context + Use of new() is not valid in this context + + '{0}': cannot specify both a constraint class and the 'unmanaged' constraint '{0}': 不可在指定條件約束類型的同時,又指定 'unmanaged' 條件約束 @@ -952,6 +977,11 @@ <切換運算式> + + target-typed object creation + target-typed object creation + + tuple equality 元組相等 @@ -2022,11 +2052,6 @@ 運算子 '{0}' 不可套用至類型為 '{1}' 的運算元 - - Operator '{0}' cannot be applied to operand '{1}' - 運算子 '{0}' 不可套用至運算元 '{1}' - - Keyword 'this' is not valid in a static property, static method, or static field initializer 關鍵字 'this' 在靜態屬性、靜態方法或靜態欄位初始設定式中無效。 @@ -2067,11 +2092,6 @@ 運算子 '{0}' 在類型為 '{1}' 和 '{2}' 的運算元上模稜兩可 - - Operator '{0}' is ambiguous on operands 'default' and 'default' - 運算子 '{0}' 在運算元 'default' 和 'default' 不明確 - - Operator '{0}' is ambiguous on an operand of type '{1}' 運算子 '{0}' 在類型為 '{1}' 的運算元上模稜兩可 @@ -5396,8 +5416,8 @@ A catch() block after a catch (System.Exception e) block can catch non-CLS excep - A new expression requires (), [], or {} after type - new 運算式在類型後需要有 ()、[] 或 {} + A new expression requires an argument list or (), [], or {} after type + new 運算式在類型後需要有 ()、[] 或 {} From 14a7dc99e3a0f7497f4563d5185debc0dfacee4f Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Wed, 29 Jan 2020 16:14:52 +0330 Subject: [PATCH 24/41] Regenerate compiler code --- .../CSharp/Portable/Generated/BoundNodes.xml.Generated.cs | 2 +- .../Portable/Generated/Syntax.xml.Internal.Generated.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs b/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs index 14d542372064f..3d2e857013989 100644 --- a/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs @@ -5487,7 +5487,7 @@ public BoundUnconvertedObjectCreationExpression(SyntaxNode syntax, ImmutableArra : base(BoundKind.UnconvertedObjectCreationExpression, syntax, null, hasErrors || arguments.HasErrors()) { - Debug.Assert(!arguments.IsDefault, "Field 'arguments' cannot be null (use Null=\"allow\" in BoundNodes.xml to remove this check)"); + RoslynDebug.Assert(!arguments.IsDefault, "Field 'arguments' cannot be null (use Null=\"allow\" in BoundNodes.xml to remove this check)"); this.Arguments = arguments; this.ArgumentNamesOpt = argumentNamesOpt; diff --git a/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Internal.Generated.cs b/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Internal.Generated.cs index 065f6593f52b7..0b0ecdf97f7c8 100644 --- a/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Internal.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Internal.Generated.cs @@ -6237,7 +6237,7 @@ static InitializerExpressionSyntax() internal abstract partial class BaseObjectCreationExpressionSyntax : ExpressionSyntax { - internal BaseObjectCreationExpressionSyntax(SyntaxKind kind, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations) + internal BaseObjectCreationExpressionSyntax(SyntaxKind kind, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations) : base(kind, diagnostics, annotations) { } @@ -6269,7 +6269,7 @@ internal sealed partial class ImplicitObjectCreationExpressionSyntax : BaseObjec internal readonly ArgumentListSyntax? argumentList; internal readonly InitializerExpressionSyntax? initializer; - internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken newKeyword, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations) + internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken newKeyword, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations) : base(kind, diagnostics, annotations) { this.SlotCount = 3; @@ -6362,10 +6362,10 @@ public ImplicitObjectCreationExpressionSyntax Update(SyntaxToken newKeyword, Arg return this; } - internal override GreenNode SetDiagnostics(DiagnosticInfo[] diagnostics) + internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics) => new ImplicitObjectCreationExpressionSyntax(this.Kind, this.newKeyword, this.argumentList, this.initializer, diagnostics, GetAnnotations()); - internal override GreenNode SetAnnotations(SyntaxAnnotation[] annotations) + internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations) => new ImplicitObjectCreationExpressionSyntax(this.Kind, this.newKeyword, this.argumentList, this.initializer, GetDiagnostics(), annotations); internal ImplicitObjectCreationExpressionSyntax(ObjectReader reader) From e6a448f9047d6049d9a66a283a347e682ec42b5f Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Wed, 29 Jan 2020 17:45:47 +0330 Subject: [PATCH 25/41] Fixup merge --- .../Portable/Binder/Binder_Operators.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs index c8baa3dc8936a..f3c62193c5971 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs @@ -709,18 +709,6 @@ private static void ReportBinaryOperatorError(ExpressionSyntax node, DiagnosticB Error(diagnostics, ErrorCode.ERR_BadOpOnNullOrDefaultOrNew, node, operatorToken.Text, "default"); return; } - else if (leftDefault && right.Type is TypeParameterSymbol) - { - Debug.Assert(!right.Type.IsReferenceType); - Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnUnconstrainedDefault, node, operatorToken.Text, right.Type); - return; - } - else if (rightDefault && left.Type is TypeParameterSymbol) - { - Debug.Assert(!left.Type.IsReferenceType); - Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnUnconstrainedDefault, node, operatorToken.Text, left.Type); - return; - } } if ((leftDefault || left.IsTypelessNew()) && @@ -729,6 +717,18 @@ private static void ReportBinaryOperatorError(ExpressionSyntax node, DiagnosticB Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnDefaultOrNew, node, operatorToken.Text, left.Display, right.Display); return; } + else if (leftDefault && right.Type is TypeParameterSymbol) + { + Debug.Assert(!right.Type.IsReferenceType); + Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnUnconstrainedDefault, node, operatorToken.Text, right.Type); + return; + } + else if (rightDefault && left.Type is TypeParameterSymbol) + { + Debug.Assert(!left.Type.IsReferenceType); + Error(diagnostics, ErrorCode.ERR_AmbigBinaryOpsOnUnconstrainedDefault, node, operatorToken.Text, left.Type); + return; + } ErrorCode errorCode = resultKind == LookupResultKind.Ambiguous ? ErrorCode.ERR_AmbigBinaryOps : // Operator '{0}' is ambiguous on operands of type '{1}' and '{2}' From 456666b9d3e7c5764df7c8ecdca08ac9e9f4d770 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 11 Feb 2020 20:36:34 +0330 Subject: [PATCH 26/41] Revert code --- src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs b/src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs index 564fcd53f16d0..48a5148ed9959 100644 --- a/src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs @@ -287,7 +287,7 @@ protected SyntaxToken CurrentToken { get { - return _currentToken ??= this.FetchCurrentToken(); + return _currentToken ?? (_currentToken = this.FetchCurrentToken()); } } From 0ae0f80b0386464acab4e66578fbb7d69c655302 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 11 Feb 2020 20:50:42 +0330 Subject: [PATCH 27/41] Capture use-site diagnostics --- .../CSharp/Portable/Binder/Binder_Conversions.cs | 9 ++++++--- .../CSharp/Portable/Binder/Binder_TupleOperators.cs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs index a2396f7222f93..f62e664f72823 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs @@ -132,7 +132,7 @@ protected BoundExpression CreateConversion( if (conversion.IsObjectCreation) { - return ConvertObjectCreationExpression((BoundUnconvertedObjectCreationExpression)source, isCast, destination, diagnostics); + return ConvertObjectCreationExpression(syntax, (BoundUnconvertedObjectCreationExpression)source, isCast, destination, diagnostics); } if (conversion.IsUserDefined) @@ -162,7 +162,7 @@ protected BoundExpression CreateConversion( { WasCompilerGenerated = wasCompilerGenerated }; } - private BoundExpression ConvertObjectCreationExpression(BoundUnconvertedObjectCreationExpression node, bool isCast, TypeSymbol destination, DiagnosticBag diagnostics) + private BoundExpression ConvertObjectCreationExpression(SyntaxNode syntax, BoundUnconvertedObjectCreationExpression node, bool isCast, TypeSymbol destination, DiagnosticBag diagnostics) { var arguments = AnalyzedArguments.GetInstance(node.Arguments, node.ArgumentRefKindsOpt, node.ArgumentNamesOpt); BoundExpression expr = BindObjectCreationExpression(node, destination.StrippedType(), arguments, diagnostics); @@ -172,7 +172,8 @@ private BoundExpression ConvertObjectCreationExpression(BoundUnconvertedObjectCr // if the destination is nullable, in which case we // target the underlying type e.g. `S? x = new();` // is actually identical to `S? x = new S();`. - var conversion = new Conversion(ConversionKind.ImplicitNullable, Conversion.IdentityUnderlying); + HashSet useSiteDiagnostics = null; + var conversion = Conversions.ClassifyStandardConversion(null, expr.Type, destination, ref useSiteDiagnostics); expr = new BoundConversion( node.Syntax, operand: expr, @@ -182,6 +183,8 @@ private BoundExpression ConvertObjectCreationExpression(BoundUnconvertedObjectCr conversionGroupOpt: new ConversionGroup(conversion), constantValueOpt: expr.ConstantValue, type: destination); + + diagnostics.Add(syntax, useSiteDiagnostics); } arguments.Free(); return expr; diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs b/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs index cfcdcf7e2115a..caebd11e46d3a 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_TupleOperators.cs @@ -325,7 +325,7 @@ internal BoundExpression GiveTupleTypeToTypelessExpressionIfNeeded(BoundExpressi if (expr is BoundUnconvertedObjectCreationExpression objectCreation) { - return ConvertObjectCreationExpression(objectCreation, isCast: false, targetType, diagnostics); + return ConvertObjectCreationExpression(expr.Syntax, objectCreation, isCast: false, targetType, diagnostics); } } From aa48a6111c913051f41d75c72855d2bc41aa5ecb Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 11 Feb 2020 22:42:06 +0330 Subject: [PATCH 28/41] Tweaks --- src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs | 1 + .../Lowering/LocalRewriter/LocalRewriter_TupleBinaryOperator.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs index c6d311692b12d..3b71843b5e592 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs @@ -958,6 +958,7 @@ private BoundCall BindInvocationExpressionContinued( var boundWithErrors = unboundLambda.BindForErrorRecovery(); diagnostics.AddRange(boundWithErrors.Diagnostics); break; + case BoundUnconvertedObjectCreationExpression _: case BoundTupleLiteral _: // Tuple literals can contain unbound lambdas or switch expressions. _ = BindToNaturalType(argument, diagnostics); diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_TupleBinaryOperator.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_TupleBinaryOperator.cs index 1d32550c927d0..8a2d8dd3063f1 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_TupleBinaryOperator.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_TupleBinaryOperator.cs @@ -226,6 +226,7 @@ bool conversionMustBePerformedOnOriginalExpression(BoundConversion expr, Convers case ConversionKind.SwitchExpression: // a switch expression must have its arms converted case ConversionKind.StackAllocToPointerType: // a stack alloc is not well-defined without an enclosing conversion case ConversionKind.StackAllocToSpanType: + case ConversionKind.ObjectCreation: return true; default: return false; From e19c690cecd86b08bfd6c51d629c86532be11b48 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 11 Feb 2020 22:44:54 +0330 Subject: [PATCH 29/41] Fix formatting --- ...perationTests_IObjectCreationExpression.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IObjectCreationExpression.cs b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IObjectCreationExpression.cs index f9b5e05905879..d97b7091d858f 100644 --- a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IObjectCreationExpression.cs +++ b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IObjectCreationExpression.cs @@ -357,12 +357,12 @@ public void ImplicitObjectCreationWithCollectionInitializer() using System.Collections.Generic; class C { - private readonly int field; - public void M1(int x) - { - int y = 0; - List x1 = /**/new() { x, y, field }/**/; - } + private readonly int field; + public void M1(int x) + { + int y = 0; + List x1 = /**/new() { x, y, field }/**/; + } } "; string expectedOperationTree = @" @@ -400,8 +400,8 @@ public void M1(int x) "; var expectedDiagnostics = new DiagnosticDescription[] { // file.cs(5,23): warning CS0649: Field 'C.field' is never assigned to, and will always have its default value 0 - // private readonly int field; - Diagnostic(ErrorCode.WRN_UnassignedInternalField, "field").WithArguments("C.field", "0").WithLocation(5, 23) + // private readonly int field; + Diagnostic(ErrorCode.WRN_UnassignedInternalField, "field").WithArguments("C.field", "0").WithLocation(5, 26) }; VerifyOperationTreeAndDiagnosticsForTest(source, expectedOperationTree, expectedDiagnostics, parseOptions: ImplicitObjectCreationOptions); @@ -1714,12 +1714,12 @@ public void ObjectCreationWithCollectionInitializer() class C { - private readonly int field; - public void M1(int x) - { - int y = 0; - var x1 = /**/new List { x, y, field }/**/; - } + private readonly int field; + public void M1(int x) + { + int y = 0; + var x1 = /**/new List { x, y, field }/**/; + } } "; string expectedOperationTree = @" @@ -1757,8 +1757,8 @@ public void M1(int x) "; var expectedDiagnostics = new DiagnosticDescription[] { // CS0649: Field 'C.field' is never assigned to, and will always have its default value 0 - // private readonly int field; - Diagnostic(ErrorCode.WRN_UnassignedInternalField, "field").WithArguments("C.field", "0").WithLocation(6, 23) + // private readonly int field; + Diagnostic(ErrorCode.WRN_UnassignedInternalField, "field").WithArguments("C.field", "0").WithLocation(6, 26) }; VerifyOperationTreeAndDiagnosticsForTest(source, expectedOperationTree, expectedDiagnostics); From b97cac0cb68ea5c4fc51fd3b96711f406aa75780 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 11 Feb 2020 23:43:56 +0330 Subject: [PATCH 30/41] Address PR feedback on tests --- .../TargetTypedObjectCreationTests.cs | 159 +++++++++++------- .../TargetTypedObjectCreationParsingTests.cs | 8 +- 2 files changed, 99 insertions(+), 68 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs index f7677519c37c3..bf4bd2bd720c0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs @@ -594,7 +594,37 @@ void M() } [Fact] - public void TestTargetType_TypeParameter() + public void TestTypeParameter() + { + var source = @" +using System; + +struct S +{ + static void M1() where T : struct + { + Console.Write((T)new()); + } + static void M2() where T : new() + { + Console.Write((T)new()); + } + + public static void Main() + { + M1(); + M2(); + } +} +"; + + var comp = CreateCompilation(source, options: TestOptions.DebugExe).VerifyDiagnostics(); + + CompileAndVerify(comp, expectedOutput: "SS"); + } + + [Fact] + public void TestTypeParameter_ErrorCases() { var source = @" class C @@ -612,15 +642,6 @@ void M() TClass x0 = new(); var x1 = (TClass)new(); } - { - TStruct x0 = new(); // ok - var x1 = (TStruct)new(); // ok - } - { - - TNew x0 = new(); // ok - var x1 = (TNew)new(); // ok - } } } "; @@ -1064,11 +1085,6 @@ public void TestBestType_SwitchExpression() class C { - public static void M(Func f) - { - Console.Write(f(true)); - Console.Write(f(false)); - } public static void Main() { var b = false; @@ -1092,11 +1108,6 @@ public void TestInSwitchExpression() class C { - public static void M(Func f) - { - Console.Write(f(true)); - Console.Write(f(false)); - } public static void Main() { C x = 0 switch { _ => new() }; @@ -1118,23 +1129,21 @@ public void TestInNullCoalescingAssignment() class C { - public static void M(Func f) - { - Console.Write(f(true)); - Console.Write(f(false)); - } public static void Main() { C x = null; x ??= new(); Console.Write(x); + int? i = null; + i ??= new(); + Console.Write(i); } } "; var comp = CreateCompilation(source, options: TestOptions.DebugExe).VerifyDiagnostics(); - CompileAndVerify(comp, expectedOutput: "C"); + CompileAndVerify(comp, expectedOutput: "C0"); } [Fact] @@ -1217,36 +1226,6 @@ static void M() ); } - [Fact] - public void TestTypeParameter() - { - var source = @" -using System; - -struct S -{ - static void M1() where T : struct - { - Console.Write((T)new()); - } - static void M2() where T : new() - { - Console.Write((T)new()); - } - - public static void Main() - { - M1(); - M2(); - } -} -"; - - var comp = CreateCompilation(source, options: TestOptions.DebugExe).VerifyDiagnostics(); - - CompileAndVerify(comp, expectedOutput: "SS"); - } - [Fact] public void TestTypeParameterInitializer() { @@ -1307,7 +1286,7 @@ public Dog() {} } public class Animal { - MODIFIER Animal() {} + public Animal() {} public static implicit operator Animal(Dog dog) => throw null; } @@ -1321,14 +1300,9 @@ public static void Main() } "; - var comp1 = CreateCompilation(source.Replace("MODIFIER", "private"), options: TestOptions.DebugExe).VerifyDiagnostics( - // (17,11): error CS0122: 'Animal.Animal()' is inaccessible due to its protection level - // M(new()); - Diagnostic(ErrorCode.ERR_BadAccess, "new()").WithArguments("Animal.Animal()").WithLocation(17, 11) - ); - var comp2 = CreateCompilation(source.Replace("MODIFIER", "public"), options: TestOptions.DebugExe).VerifyDiagnostics( + var comp = CreateCompilation(source, options: TestOptions.DebugExe).VerifyDiagnostics( ); - CompileAndVerify(comp2, expectedOutput: "Animal"); + CompileAndVerify(comp, expectedOutput: "Animal"); } [ConditionalFact(typeof(DesktopOnly), Reason = ConditionalSkipReason.RestrictedTypesNeedDesktop)] @@ -3922,5 +3896,62 @@ static void Main() Diagnostic(ErrorCode.ERR_BadSKknown, "System").WithArguments("System", "namespace", "type").WithLocation(6, 11) ); } + + [Fact] + public void TestSpeculativeModel01() + { + string source = @" +class C +{ + static void Main() + { + int i = 2; + } +} +"; + var comp = CreateCompilation(source, parseOptions: TargetTypedObjectCreationTestOptions); + + var tree = comp.SyntaxTrees.First(); + var model = comp.GetSemanticModel(tree); + var node = tree.GetCompilationUnitRoot().DescendantNodes().OfType().Single(); + int nodeLocation = node.Location.SourceSpan.Start; + + var newExpression = SyntaxFactory.ParseExpression("new()"); + var typeInfo = model.GetSpeculativeTypeInfo(nodeLocation, newExpression, SpeculativeBindingOption.BindAsExpression); + Assert.Null(typeInfo.Type); + var symbolInfo = model.GetSpeculativeSymbolInfo(nodeLocation, newExpression, SpeculativeBindingOption.BindAsExpression); + Assert.True(symbolInfo.IsEmpty); + } + + [Fact] + public void TestSpeculativeModel02() + { + string source = @" +class C +{ + static void M(int i) {} + static void Main() + { + M(42); + } +} +"; + var comp = CreateCompilation(source, parseOptions: TargetTypedObjectCreationTestOptions); + + var tree = comp.SyntaxTrees.First(); + var model = comp.GetSemanticModel(tree); + var node = tree.GetCompilationUnitRoot().DescendantNodes().OfType().Single(); + int nodeLocation = node.Location.SourceSpan.Start; + + var modifiedNode = (ExpressionStatementSyntax)SyntaxFactory.ParseStatement("M(new());"); + Assert.True(model.TryGetSpeculativeSemanticModel(nodeLocation, modifiedNode, out var speculativeModel)); + + var newExpression = ((InvocationExpressionSyntax)modifiedNode.Expression).ArgumentList.Arguments[0].Expression; + var symbolInfo = speculativeModel.GetSymbolInfo(newExpression); + Assert.True(symbolInfo.IsEmpty); + var typeInfo = speculativeModel.GetTypeInfo(newExpression); + Assert.True(typeInfo.ConvertedType.IsErrorType()); + Assert.True(typeInfo.Type.IsErrorType()); + } } } diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs index e977b862f983b..b616e526c042f 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs @@ -398,7 +398,7 @@ public void TestEmptyArgList() [Fact] public void TestEmptyArgList_LangVersion() { - UsingExpression("new()", options: TestOptions.Regular7_3, + UsingExpression("new()", options: TestOptions.Regular8, // (1,1): error CS8652: The feature 'target-typed object creation' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // new() Diagnostic(ErrorCode.ERR_FeatureInPreview, "new").WithArguments("target-typed object creation").WithLocation(1, 1) @@ -440,7 +440,7 @@ public void TestEmptyObjectInitializer() [Fact] public void TestEmptyObjectInitializer_LangVersion() { - UsingExpression("new(){}", options: TestOptions.Regular7_3, + UsingExpression("new(){}", options: TestOptions.Regular8, // (1,1): error CS8652: The feature 'target-typed object creation' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // new(){} Diagnostic(ErrorCode.ERR_FeatureInPreview, "new").WithArguments("target-typed object creation").WithLocation(1, 1) @@ -504,7 +504,7 @@ public void TestObjectInitializer() { N(SyntaxKind.IdentifierToken, "y"); } - } + }s N(SyntaxKind.CloseBraceToken); } } @@ -514,7 +514,7 @@ public void TestObjectInitializer() [Fact] public void TestObjectInitializer_LangVersion() { - UsingExpression("new(a,b){x=y}", options: TestOptions.Regular7_3, + UsingExpression("new(a,b){x=y}", options: TestOptions.Regular8, // (1,1): error CS8652: The feature 'target-typed object creation' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // new(1,2){x=y} Diagnostic(ErrorCode.ERR_FeatureInPreview, "new").WithArguments("target-typed object creation").WithLocation(1, 1) From c082effc97db2141087378873387b10f3d615ad5 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 11 Feb 2020 23:48:45 +0330 Subject: [PATCH 31/41] Undo accidental insertion --- .../Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs index b616e526c042f..bd5baff53521e 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/TargetTypedObjectCreationParsingTests.cs @@ -504,7 +504,7 @@ public void TestObjectInitializer() { N(SyntaxKind.IdentifierToken, "y"); } - }s + } N(SyntaxKind.CloseBraceToken); } } From e49bc5e1a260a0fbdda3eac5dab9747c8a1f706e Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 11 Feb 2020 23:57:42 +0330 Subject: [PATCH 32/41] Fix build --- src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs index f62e664f72823..1a77f94dbcef1 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs @@ -172,7 +172,7 @@ private BoundExpression ConvertObjectCreationExpression(SyntaxNode syntax, Bound // if the destination is nullable, in which case we // target the underlying type e.g. `S? x = new();` // is actually identical to `S? x = new S();`. - HashSet useSiteDiagnostics = null; + HashSet? useSiteDiagnostics = null; var conversion = Conversions.ClassifyStandardConversion(null, expr.Type, destination, ref useSiteDiagnostics); expr = new BoundConversion( node.Syntax, From 78613a43bd2d4b51db3f43142da9a9f7fd9f5dc9 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 20 Feb 2020 13:42:32 +0330 Subject: [PATCH 33/41] Use Display string for every argument expression --- .../Portable/Binder/Binder_Expressions.cs | 2 +- .../CSharp/Portable/BoundTree/Formatting.cs | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 7f87805aab860..7aa4122938136 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -319,7 +319,7 @@ internal BoundExpression BindToNaturalType(BoundExpression expression, Diagnosti { if (reportNoTargetType) { - diagnostics.Add(ErrorCode.ERR_TypelessNewNoTargetType, expr.Syntax.GetLocation()); + diagnostics.Add(ErrorCode.ERR_TypelessNewNoTargetType, expr.Syntax.GetLocation(), expr.Display); } result = BindObjectCreationForErrorRecovery(expr, diagnostics); diff --git a/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs b/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs index b080e0284c93d..f40e232d111d5 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs @@ -168,6 +168,36 @@ internal partial class BoundPassByCopy internal partial class BoundUnconvertedObjectCreationExpression { - public override object Display => "new()"; + public override object Display + { + get + { + var arguments = this.Arguments; + if (arguments.Length == 0) + { + return "new()"; + } + + var pooledBuilder = PooledStringBuilder.GetInstance(); + var builder = pooledBuilder.Builder; + var argumentDisplays = new object[arguments.Length]; + + builder.Append("new"); + builder.Append('('); + builder.Append("{0}"); + argumentDisplays[0] = arguments[0].Display; + + for (int i = 1; i < arguments.Length; i++) + { + builder.Append($", {{{i.ToString()}}}"); + argumentDisplays[i] = arguments[i].Display; + } + + builder.Append(')'); + + var format = pooledBuilder.ToStringAndFree(); + return FormattableStringFactory.Create(format, argumentDisplays); + } + } } } From 5461453659d7683198289da5b1abc556a06479e9 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 20 Feb 2020 15:26:07 +0330 Subject: [PATCH 34/41] Update baseline --- .../TargetTypedObjectCreationTests.cs | 208 +++++++++--------- 1 file changed, 105 insertions(+), 103 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs index bf4bd2bd720c0..22788574612a4 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs @@ -292,9 +292,10 @@ public static void Main() "; var comp = CreateCompilation(source, options: TestOptions.DebugExe, references: new[] { CSharpRef }); comp.VerifyDiagnostics( - // (9,13): error CS8754: There is no target type for new() - // d.M(new()); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(9, 13)); + // (9,13): error CS8754: There is no target type for 'new()' + // d.M(new()); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(9, 13) + ); } [Fact] @@ -322,19 +323,19 @@ public void M() "; var comp = CreateCompilation(source, options: TestOptions.DebugDll); comp.VerifyDiagnostics( - // (14,23): error CS8754: There is no target type for new() - // Console.Write(new() as C); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(14, 23), - // (15,23): error CS8754: There is no target type for new() - // Console.Write(new() as S?); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(15, 23), - // (16,23): error CS8754: There is no target type for new() - // Console.Write(new() as TClass); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(16, 23), - // (17,23): error CS8754: There is no target type for new() - // Console.Write(new() as TNew); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(17, 23) - ); + // (14,23): error CS8754: There is no target type for 'new()' + // Console.Write(new() as C); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(14, 23), + // (15,23): error CS8754: There is no target type for 'new()' + // Console.Write(new() as S?); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(15, 23), + // (16,23): error CS8754: There is no target type for 'new()' + // Console.Write(new() as TClass); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(16, 23), + // (17,23): error CS8754: There is no target type for 'new()' + // Console.Write(new() as TNew); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(17, 23) + ); } [Fact] @@ -368,15 +369,15 @@ class C { void M() { - var x = new(); + var x = new(2, 3); } } "; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (6,17): error CS8755: There is no target type for new() expression - // var x = new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 17) + // (6,17): error CS8754: There is no target type for 'new(int, int)' + // var x = new(5); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new(2, 3)").WithArguments("new(int, int)").WithLocation(6, 17) ); } @@ -394,9 +395,9 @@ void M() "; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (6,13): error CS8754: There is no target type for new() + // (6,13): error CS8754: There is no target type for 'new()' // _ = new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 13) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 13) ); } @@ -986,9 +987,9 @@ public static void Main() "; var comp = CreateCompilation(source, options: TestOptions.DebugExe); comp.VerifyDiagnostics( - // (6,22): error CS8755: There is no target type for new() expression + // (6,22): error CS8754: There is no target type for 'new()' // var (_, _) = new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 22), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 22), // (6,22): error CS8131: Deconstruct assignment requires an expression with a type on the right-hand-side. // var (_, _) = new(); Diagnostic(ErrorCode.ERR_DeconstructRequiresExpression, "new()").WithLocation(6, 22), @@ -1004,9 +1005,9 @@ public static void Main() // (6,17): error CS8183: Cannot infer the type of implicitly-typed discard. // var (_, _) = new(); Diagnostic(ErrorCode.ERR_DiscardTypeInferenceFailed, "_").WithLocation(6, 17), - // (7,26): error CS8755: There is no target type for new() expression + // (7,26): error CS8754: There is no target type for 'new()' // (var _, var _) = new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(7, 26), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(7, 26), // (7,26): error CS8131: Deconstruct assignment requires an expression with a type on the right-hand-side. // (var _, var _) = new(); Diagnostic(ErrorCode.ERR_DeconstructRequiresExpression, "new()").WithLocation(7, 26), @@ -1022,9 +1023,9 @@ public static void Main() // (7,17): error CS8183: Cannot infer the type of implicitly-typed discard. // (var _, var _) = new(); Diagnostic(ErrorCode.ERR_DiscardTypeInferenceFailed, "var _").WithLocation(7, 17), - // (8,22): error CS8755: There is no target type for new() expression + // (8,22): error CS8754: There is no target type for 'new()' // (C _, C _) = new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(8, 22), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(8, 22), // (8,22): error CS8131: Deconstruct assignment requires an expression with a type on the right-hand-side. // (C _, C _) = new(); Diagnostic(ErrorCode.ERR_DeconstructRequiresExpression, "new()").WithLocation(8, 22) @@ -1656,9 +1657,9 @@ public static void Main() // (6,13): error CS0103: The name 'a' does not exist in the current context // new(a) { x }; Diagnostic(ErrorCode.ERR_NameNotInContext, "a").WithArguments("a").WithLocation(6, 13), - // (7,9): error CS8755: There is no target type for new() expression + // (7,9): error CS8754: There is no target type for 'new()' // new() { x }; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new() { x }").WithLocation(7, 9), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new() { x }").WithArguments("new()").WithLocation(7, 9), // (7,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // new() { x }; Diagnostic(ErrorCode.ERR_IllegalStatement, "new() { x }").WithLocation(7, 9), @@ -1918,12 +1919,12 @@ static void Main() var comp = CreateCompilation(source, options: TestOptions.DebugExe); comp.VerifyDiagnostics( - // (6,16): error CS8754: There is no target type for new() expression + // (6,16): error CS8754: There is no target type for 'new()' // using (new()) - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 16), - // (10,24): error CS8754: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 16), + // (10,24): error CS8754: There is no target type for 'new()' // using (var x = new()) - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(10, 24), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(10, 24), // (14,39): error CS0144: Cannot create an instance of the abstract class or interface 'IDisposable' // using (System.IDisposable x = new()) Diagnostic(ErrorCode.ERR_NoNewAbstract, "new()").WithArguments("System.IDisposable").WithLocation(14, 39) @@ -1994,9 +1995,9 @@ async System.Threading.Tasks.Task M2() var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (6,15): error CS8754: There is no target type for new() expression + // (6,15): error CS8754: There is no target type for 'new()' // await new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 15), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 15), // (11,19): error CS0103: The name 'a' does not exist in the current context // await new(a); Diagnostic(ErrorCode.ERR_NameNotInContext, "a").WithArguments("a").WithLocation(11, 19) @@ -2139,9 +2140,9 @@ static void M() "; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (6,30): error CS8755: There is no target type for new() expression + // (6,30): error CS8754: There is no target type for 'new()' // var x = new { Prop = new() }; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 30) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 30) ); } @@ -2166,18 +2167,18 @@ static void M() "; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (6,17): error CS8755: There is no target type for new() expression + // (6,17): error CS8754: There is no target type for 'new()' // C v1 = +new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 17), - // (7,17): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 17), + // (7,17): error CS8754: There is no target type for 'new()' // C v2 = -new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(7, 17), - // (8,17): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(7, 17), + // (8,17): error CS8754: There is no target type for 'new()' // C v3 = ~new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(8, 17), - // (9,17): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(8, 17), + // (9,17): error CS8754: There is no target type for 'new()' // C v4 = !new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(9, 17), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(9, 17), // (10,18): error CS1059: The operand of an increment or decrement operator must be a variable, property or indexer // C v5 = ++new(); Diagnostic(ErrorCode.ERR_IncrementLvalueExpected, "new()").WithLocation(10, 18), @@ -2297,9 +2298,9 @@ static void Main() // (6,15): error CS0117: 'new()' does not contain a definition for 'ToString' // new().ToString(); Diagnostic(ErrorCode.ERR_NoSuchMember, "ToString").WithArguments("new()", "ToString").WithLocation(6, 15), - // (7,9): error CS8754: There is no target type for new() + // (7,9): error CS8754: There is no target type for 'new()' // new()[0].ToString(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(7, 9) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(7, 9) ); } @@ -2395,9 +2396,9 @@ static void Main() "; var comp = CreateCompilation(source, options: TestOptions.DebugExe); comp.VerifyDiagnostics( - // (6,17): error CS8754: There is no target type for new() expression + // (6,17): error CS8754: There is no target type for 'new()' // switch (new()) - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 17), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 17), // (10,17): warning CS0162: Unreachable code detected // break; Diagnostic(ErrorCode.WRN_UnreachableCode, "break").WithLocation(10, 17) @@ -2529,9 +2530,9 @@ static void Main() "; var comp = CreateCompilation(source, options: TestOptions.DebugExe); comp.VerifyDiagnostics( - // (6,15): error CS8755: There is no target type for new() expression + // (6,15): error CS8754: There is no target type for 'new()' // lock (new()) - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 15) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 15) ); } @@ -2628,9 +2629,9 @@ static void Main() // (6,13): error CS0233: '?' does not have a predefined size, therefore sizeof can only be used in an unsafe context // _ = sizeof(new()); Diagnostic(ErrorCode.ERR_SizeofUnsafe, "sizeof(").WithArguments("?").WithLocation(6, 13), - // (6,20): error CS8755: There is no target type for new() expression + // (6,20): error CS8754: There is no target type for 'new()' // _ = sizeof(new()); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 20) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 20) ); } @@ -2657,9 +2658,9 @@ static void Main() // (6,20): error CS1002: ; expected // _ = typeof(new()); Diagnostic(ErrorCode.ERR_SemicolonExpected, "new").WithLocation(6, 20), - // (6,20): error CS8755: There is no target type for new() expression + // (6,20): error CS8754: There is no target type for 'new()' // _ = typeof(new()); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 20), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 20), // (6,25): error CS1002: ; expected // _ = typeof(new()); Diagnostic(ErrorCode.ERR_SemicolonExpected, ")").WithLocation(6, 25), @@ -2838,12 +2839,12 @@ static void M() "; var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (6,18): error CS8755: There is no target type for new() expression + // (6,18): error CS8754: There is no target type for 'new()' // var p = *new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 18), - // (7,17): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 18), + // (7,17): error CS8754: There is no target type for 'new()' // var q = new()->F; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(7, 17) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(7, 17) ); } @@ -3122,9 +3123,10 @@ static void M1() var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (7,14): error CS8755: There is no target type for new() expression + // (7,14): error CS8754: There is no target type for 'new()' // d.M2(new()); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(7, 14)); + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(7, 14) + ); } [Fact] @@ -3228,26 +3230,26 @@ static void Main() // var n = new() <= new(); Diagnostic(ErrorCode.ERR_AmbigBinaryOpsOnDefaultOrNew, "new() <= new()").WithArguments("<=", "new()", "new()").WithLocation(19, 17), // (20,17): error CS8315: Operator '==' is ambiguous on operands 'new()' and 'new()' - // var o = new() == new(); // ambiguous + // var o = new() == new(); // void ImplicitObjectCreation Diagnostic(ErrorCode.ERR_AmbigBinaryOpsOnDefaultOrNew, "new() == new()").WithArguments("==", "new()", "new()").WithLocation(20, 17), // (21,17): error CS8315: Operator '!=' is ambiguous on operands 'new()' and 'new()' - // var p = new() != new(); // ambiguous + // var p = new() != new(); // void ImplicitObjectCreation Diagnostic(ErrorCode.ERR_AmbigBinaryOpsOnDefaultOrNew, "new() != new()").WithArguments("!=", "new()", "new()").WithLocation(21, 17), - // (22,17): error CS8755: There is no target type for new() expression + // (22,17): error CS8754: There is no target type for 'new()' // var q = new() && new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(22, 17), - // (22,26): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(22, 17), + // (22,26): error CS8754: There is no target type for 'new()' // var q = new() && new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(22, 26), - // (23,17): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(22, 26), + // (23,17): error CS8754: There is no target type for 'new()' // var r = new() || new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(23, 17), - // (23,26): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(23, 17), + // (23,26): error CS8754: There is no target type for 'new()' // var r = new() || new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(23, 26), - // (24,17): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(23, 26), + // (24,17): error CS8754: There is no target type for 'new()' // var s = new() ?? new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(24, 17) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(24, 17) ); } @@ -3285,18 +3287,18 @@ static void Main() var comp = CreateCompilation(source); comp.VerifyDiagnostics( - // (22,13): error CS8755: There is no target type for new() expression + // (22,13): error CS8754: There is no target type for 'new()' // _ = new() && 1; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(22, 13), - // (23,13): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(22, 13), + // (23,13): error CS8754: There is no target type for 'new()' // _ = new() || 1; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(23, 13), - // (24,13): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(23, 13), + // (24,13): error CS8754: There is no target type for 'new()' // _ = new() ?? 1; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(24, 13), - // (25,13): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(24, 13), + // (25,13): error CS8754: There is no target type for 'new()' // _ = new() ?? default(int?); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(25, 13) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(25, 13) ); } @@ -3340,12 +3342,12 @@ static void Main() // (13,13): error CS0020: Division by constant zero // _ = 1 % new(); Diagnostic(ErrorCode.ERR_IntDivByZero, "1 % new()").WithLocation(13, 13), - // (22,18): error CS8755: There is no target type for new() expression + // (22,18): error CS8754: There is no target type for 'new()' // _ = 1 && new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(22, 18), - // (23,18): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(22, 18), + // (23,18): error CS8754: There is no target type for 'new()' // _ = 1 || new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(23, 18), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(23, 18), // (25,13): error CS0019: Operator '??' cannot be applied to operands of type 'int' and 'new()' // _ = 1 ?? new(); Diagnostic(ErrorCode.ERR_BadBinaryOps, "1 ?? new()").WithArguments("??", "int", "new()").WithLocation(25, 13) @@ -3366,9 +3368,9 @@ static void Main() var comp = CreateCompilation(text, options: TestOptions.DebugExe); comp.VerifyDiagnostics( - // (6,27): error CS8755: There is no target type for new() expression + // (6,27): error CS8754: There is no target type for 'new()' // foreach (int x in new()) { } - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 27) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 27) ); } @@ -3388,13 +3390,13 @@ static void Main() "; var compilation = CreateCompilation(source, options: TestOptions.DebugExe); compilation.VerifyDiagnostics( - // (6,27): error CS8754: There is no target type for new() - // var q = from x in new() select x; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 27), - // (7,43): error CS1942: The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'. - // var p = from x in new int[] { 1 } select new(); - Diagnostic(ErrorCode.ERR_QueryTypeInferenceFailed, "select").WithArguments("select", "Select").WithLocation(7, 43) - ); + // (6,27): error CS8754: There is no target type for 'new()' + // var q = from x in new() select x; + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 27), + // (7,43): error CS1942: The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'. + // var p = from x in new int[] { 1 } select new(); + Diagnostic(ErrorCode.ERR_QueryTypeInferenceFailed, "select").WithArguments("select", "Select").WithLocation(7, 43) + ); } [Fact] @@ -3415,15 +3417,15 @@ void M() var comp = CreateCompilation(text, options: TestOptions.DebugDll); comp.VerifyDiagnostics( - // (6,19): error CS8755: There is no target type for new() expression + // (6,19): error CS8754: There is no target type for 'new()' // bool v1 = new() is long; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(6, 19), - // (7,19): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(6, 19), + // (7,19): error CS8754: There is no target type for 'new()' // bool v2 = new() is string; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(7, 19), - // (8,19): error CS8755: There is no target type for new() expression + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(7, 19), + // (8,19): error CS8754: There is no target type for 'new()' // bool v3 = new() is new(); - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(8, 19), + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(8, 19), // (10,27): error CS0150: A constant value is expected // bool v5 = this is new(); Diagnostic(ErrorCode.ERR_ConstantExpected, "new()").WithLocation(10, 27) @@ -3445,9 +3447,9 @@ static void Main() }"; var comp = CreateCompilation(text).VerifyDiagnostics( - // (7,32): error CS8755: There is no target type for new() expression + // (7,32): error CS8754: There is no target type for 'new()' // Func f = () => new() ?? "hello"; - Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithLocation(7, 32) + Diagnostic(ErrorCode.ERR_TypelessNewNoTargetType, "new()").WithArguments("new()").WithLocation(7, 32) ); } From 082390353123f336151d48accc3f8c64618d9ab6 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 20 Feb 2020 15:26:13 +0330 Subject: [PATCH 35/41] Update resources --- src/Compilers/CSharp/Portable/CSharpResources.resx | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf | 4 ++-- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 8e2df2f801857..d284d2b115a2b 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6005,7 +6005,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Use of new() is not valid in this context - There is no target type for new() + There is no target type for '{0}' target-typed object creation diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 880af4b2a4803..ebad3977f87e5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index b85784433a3c8..de0cff25b7e70 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 01e357d3594b6..a8f7ec2e63e9f 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index e5ec49ffaf93d..ce200d74c948f 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 4a776a1e91afc..1d681b6896304 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 4c6895fe57c81..8bde0deb1dfda 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index ec3d0a161fadc..58ca4ac298679 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 62b8e8fa44699..88949dc5260d8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 929a60baff02c..6f057ade2db67 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index a3818806b3cb2..d9348fe838888 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index d169a261b32d1..3fcc89bfc7e19 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index aed39c98d1832..e3d38eb142142 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index f9d51cf40beee..ede15bc888c3e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -493,8 +493,8 @@ - There is no target type for new() - There is no target type for new() + There is no target type for '{0}' + There is no target type for '{0}' From 49887e77e25ea0de581d106978de63309a116cf1 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 20 Feb 2020 15:31:01 +0330 Subject: [PATCH 36/41] Permit throw new() usage --- .../CSharp/Portable/Binder/Binder_Statements.cs | 7 ------- .../Semantics/TargetTypedObjectCreationTests.cs | 17 +++++++++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs index def975b7a5683..0d7109803918c 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs @@ -374,13 +374,6 @@ internal BoundStatement BindPossibleEmbeddedStatement(StatementSyntax node, Diag private BoundExpression BindThrownExpression(ExpressionSyntax exprSyntax, DiagnosticBag diagnostics, ref bool hasErrors) { var boundExpr = BindValue(exprSyntax, diagnostics, BindValueKind.RValue); - if (boundExpr.IsTypelessNew()) - { - // NOTE This only disallows direct usage. One can simply bypass this by wrapping new() in a switch expression - diagnostics.Add(ErrorCode.ERR_TypelessNewNotValid, exprSyntax.Location); - hasErrors = true; - } - if (Compilation.LanguageVersion < MessageID.IDS_FeatureSwitchExpression.RequiredVersion()) { // This is the pre-C# 8 algorithm for binding a thrown expression. diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs index 22788574612a4..5c559f272c4f5 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TargetTypedObjectCreationTests.cs @@ -2312,16 +2312,21 @@ class C { static void Main() { - throw new(); + throw new(""message""); } } "; var comp = CreateCompilation(source, options: TestOptions.DebugExe); - comp.VerifyDiagnostics( - // (6,15): error CS8754: Use of 'new()' is not valid in this context - // throw new(); - Diagnostic(ErrorCode.ERR_TypelessNewNotValid, "new()").WithLocation(6, 15) - ); + comp.VerifyDiagnostics(); + + var tree = comp.SyntaxTrees.First(); + var model = comp.GetSemanticModel(tree); + var nodes = tree.GetCompilationUnitRoot().DescendantNodes(); + + var def = nodes.OfType().First(); + Assert.Equal("System.Exception", model.GetTypeInfo(def).Type.ToTestDisplayString()); + Assert.Equal("System.Exception", model.GetTypeInfo(def).ConvertedType.ToTestDisplayString()); + Assert.Equal("System.Exception..ctor(System.String message)", model.GetSymbolInfo(def).Symbol.ToTestDisplayString()); } [Fact] From c6aba72594d0e682e84b9d67eb3d133241bc7dcf Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 20 Feb 2020 18:42:45 +0330 Subject: [PATCH 37/41] Add wasTargetTyped flag for object creation node --- .../Portable/Binder/Binder_Conversions.cs | 2 +- .../Portable/Binder/Binder_Expressions.cs | 4 +++- .../CSharp/Portable/BoundTree/BoundNodes.xml | 1 + .../BoundTree/BoundObjectCreationExpression.cs | 11 +++++++++-- .../Generated/BoundNodes.xml.Generated.cs | 18 +++++++++++------- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs index 1a77f94dbcef1..77bbbf056adb6 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs @@ -197,7 +197,7 @@ private BoundExpression BindObjectCreationExpression(BoundUnconvertedObjectCreat { case TypeKind.Struct: case TypeKind.Class when !type.IsAnonymousType: // We don't want to enable object creation with unspeakable types - return BindClassCreationExpression(syntax, type.Name, typeNode: syntax, (NamedTypeSymbol)type, arguments, diagnostics, node.InitializerOpt); + return BindClassCreationExpression(syntax, type.Name, typeNode: syntax, (NamedTypeSymbol)type, arguments, diagnostics, node.InitializerOpt, wasTargetTyped: true); case TypeKind.TypeParameter: return BindTypeParameterCreationExpression(syntax, (TypeParameterSymbol)type, arguments, node.InitializerOpt, typeSyntax: syntax, diagnostics); case TypeKind.Delegate: diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 7aa4122938136..a7141cff9131a 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -4989,7 +4989,8 @@ protected BoundExpression BindClassCreationExpression( AnalyzedArguments analyzedArguments, DiagnosticBag diagnostics, InitializerExpressionSyntax initializerSyntaxOpt = null, - TypeSymbol initializerTypeOpt = null) + TypeSymbol initializerTypeOpt = null, + bool wasTargetTyped = false) { BoundExpression result = null; @@ -5108,6 +5109,7 @@ protected BoundExpression BindClassCreationExpression( argToParams, constantValueOpt, boundInitializerOpt, + wasTargetTyped, this, type, hasError); diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml index cd7097d737d98..e0571989f87c0 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml @@ -1576,6 +1576,7 @@ + diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundObjectCreationExpression.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundObjectCreationExpression.cs index 171e1b75d8e6c..084d4cf1d2345 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundObjectCreationExpression.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundObjectCreationExpression.cs @@ -12,13 +12,20 @@ internal partial class BoundObjectCreationExpression public BoundObjectCreationExpression(SyntaxNode syntax, MethodSymbol constructor, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, bool expanded, ImmutableArray argsToParamsOpt, ConstantValue constantValueOpt, BoundObjectInitializerExpressionBase initializerExpressionOpt, Binder binderOpt, TypeSymbol type, bool hasErrors = false) - : this(syntax, constructor, ImmutableArray.Empty, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, binderOpt, type, hasErrors) + : this(syntax, constructor, ImmutableArray.Empty, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, wasTargetTyped: false, binderOpt, type, hasErrors) { } public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, bool expanded, ImmutableArray argsToParamsOpt, ConstantValue constantValueOpt, BoundObjectInitializerExpressionBase initializerExpressionOpt, Binder binderOpt, TypeSymbol type) { - return this.Update(constructor, ImmutableArray.Empty, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, binderOpt, type); + return this.Update(constructor, ImmutableArray.Empty, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, wasTargetTyped: false, binderOpt, type); + } + + public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableArray constructorsGroup, ImmutableArray arguments, + ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, bool expanded, ImmutableArray argsToParamsOpt, + ConstantValue constantValueOpt, BoundObjectInitializerExpressionBase initializerExpressionOpt, Binder binderOpt, TypeSymbol type) + { + return this.Update(constructor, constructorsGroup, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, wasTargetTyped: false, binderOpt, type); } } } diff --git a/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs b/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs index 3d2e857013989..19695bb5e35d2 100644 --- a/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs @@ -5522,7 +5522,7 @@ public BoundUnconvertedObjectCreationExpression Update(ImmutableArray constructorsGroup, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, bool expanded, ImmutableArray argsToParamsOpt, ConstantValue? constantValueOpt, BoundObjectInitializerExpressionBase? initializerExpressionOpt, Binder? binderOpt, TypeSymbol type, bool hasErrors = false) + public BoundObjectCreationExpression(SyntaxNode syntax, MethodSymbol constructor, ImmutableArray constructorsGroup, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, bool expanded, ImmutableArray argsToParamsOpt, ConstantValue? constantValueOpt, BoundObjectInitializerExpressionBase? initializerExpressionOpt, bool wasTargetTyped, Binder? binderOpt, TypeSymbol type, bool hasErrors = false) : base(BoundKind.ObjectCreationExpression, syntax, type, hasErrors || arguments.HasErrors() || initializerExpressionOpt.HasErrors()) { @@ -5540,6 +5540,7 @@ public BoundObjectCreationExpression(SyntaxNode syntax, MethodSymbol constructor this.ArgsToParamsOpt = argsToParamsOpt; this.ConstantValueOpt = constantValueOpt; this.InitializerExpressionOpt = initializerExpressionOpt; + this.WasTargetTyped = wasTargetTyped; this.BinderOpt = binderOpt; } @@ -5564,15 +5565,17 @@ public BoundObjectCreationExpression(SyntaxNode syntax, MethodSymbol constructor public BoundObjectInitializerExpressionBase? InitializerExpressionOpt { get; } + public bool WasTargetTyped { get; } + public Binder? BinderOpt { get; } [DebuggerStepThrough] public override BoundNode? Accept(BoundTreeVisitor visitor) => visitor.VisitObjectCreationExpression(this); - public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableArray constructorsGroup, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, bool expanded, ImmutableArray argsToParamsOpt, ConstantValue? constantValueOpt, BoundObjectInitializerExpressionBase? initializerExpressionOpt, Binder? binderOpt, TypeSymbol type) + public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableArray constructorsGroup, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, bool expanded, ImmutableArray argsToParamsOpt, ConstantValue? constantValueOpt, BoundObjectInitializerExpressionBase? initializerExpressionOpt, bool wasTargetTyped, Binder? binderOpt, TypeSymbol type) { - if (!Symbols.SymbolEqualityComparer.ConsiderEverything.Equals(constructor, this.Constructor) || constructorsGroup != this.ConstructorsGroup || arguments != this.Arguments || argumentNamesOpt != this.ArgumentNamesOpt || argumentRefKindsOpt != this.ArgumentRefKindsOpt || expanded != this.Expanded || argsToParamsOpt != this.ArgsToParamsOpt || constantValueOpt != this.ConstantValueOpt || initializerExpressionOpt != this.InitializerExpressionOpt || binderOpt != this.BinderOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything)) + if (!Symbols.SymbolEqualityComparer.ConsiderEverything.Equals(constructor, this.Constructor) || constructorsGroup != this.ConstructorsGroup || arguments != this.Arguments || argumentNamesOpt != this.ArgumentNamesOpt || argumentRefKindsOpt != this.ArgumentRefKindsOpt || expanded != this.Expanded || argsToParamsOpt != this.ArgsToParamsOpt || constantValueOpt != this.ConstantValueOpt || initializerExpressionOpt != this.InitializerExpressionOpt || wasTargetTyped != this.WasTargetTyped || binderOpt != this.BinderOpt || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything)) { - var result = new BoundObjectCreationExpression(this.Syntax, constructor, constructorsGroup, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, binderOpt, type, this.HasErrors); + var result = new BoundObjectCreationExpression(this.Syntax, constructor, constructorsGroup, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, wasTargetTyped, binderOpt, type, this.HasErrors); result.CopyAttributes(this); return result; } @@ -9872,7 +9875,7 @@ internal abstract partial class BoundTreeRewriter : BoundTreeVisitor ImmutableArray arguments = this.VisitList(node.Arguments); BoundObjectInitializerExpressionBase? initializerExpressionOpt = (BoundObjectInitializerExpressionBase?)this.Visit(node.InitializerExpressionOpt); TypeSymbol type = this.VisitType(node.Type); - return node.Update(node.Constructor, node.ConstructorsGroup, arguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.Expanded, node.ArgsToParamsOpt, node.ConstantValueOpt, initializerExpressionOpt, node.BinderOpt, type); + return node.Update(node.Constructor, node.ConstructorsGroup, arguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.Expanded, node.ArgsToParamsOpt, node.ConstantValueOpt, initializerExpressionOpt, node.WasTargetTyped, node.BinderOpt, type); } public override BoundNode? VisitTupleLiteral(BoundTupleLiteral node) { @@ -11675,12 +11678,12 @@ public NullabilityRewriter(ImmutableDictionary Date: Wed, 26 Feb 2020 10:11:39 +0330 Subject: [PATCH 38/41] PR feedback --- .../Portable/BoundTree/BoundObjectCreationExpression.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundObjectCreationExpression.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundObjectCreationExpression.cs index 084d4cf1d2345..3abdec70db36b 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundObjectCreationExpression.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundObjectCreationExpression.cs @@ -18,14 +18,14 @@ public BoundObjectCreationExpression(SyntaxNode syntax, MethodSymbol constructor public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, bool expanded, ImmutableArray argsToParamsOpt, ConstantValue constantValueOpt, BoundObjectInitializerExpressionBase initializerExpressionOpt, Binder binderOpt, TypeSymbol type) { - return this.Update(constructor, ImmutableArray.Empty, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, wasTargetTyped: false, binderOpt, type); + return this.Update(constructor, ImmutableArray.Empty, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, this.WasTargetTyped, binderOpt, type); } public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableArray constructorsGroup, ImmutableArray arguments, ImmutableArray argumentNamesOpt, ImmutableArray argumentRefKindsOpt, bool expanded, ImmutableArray argsToParamsOpt, ConstantValue constantValueOpt, BoundObjectInitializerExpressionBase initializerExpressionOpt, Binder binderOpt, TypeSymbol type) { - return this.Update(constructor, constructorsGroup, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, wasTargetTyped: false, binderOpt, type); + return this.Update(constructor, constructorsGroup, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, constantValueOpt, initializerExpressionOpt, this.WasTargetTyped, binderOpt, type); } } } From b9e2751d0147b61a638fce56e6d863b992f0c21b Mon Sep 17 00:00:00 2001 From: Alireza Date: Wed, 26 Feb 2020 15:27:42 +0330 Subject: [PATCH 39/41] Fix merge --- .../CSharp/Portable/PublicAPI.Unshipped.txt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt b/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt index 746832ef9350f..3e7d2473ba621 100644 --- a/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt @@ -8,6 +8,12 @@ *REMOVED*static Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(string text, Microsoft.CodeAnalysis.CSharp.CSharpParseOptions options = null, string path = "", System.Text.Encoding encoding = null, System.Collections.Immutable.ImmutableDictionary diagnosticOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.SyntaxTree *REMOVED*static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ParseSyntaxTree(Microsoft.CodeAnalysis.Text.SourceText text, Microsoft.CodeAnalysis.ParseOptions options = null, string path = "", System.Collections.Immutable.ImmutableDictionary diagnosticOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.SyntaxTree *REMOVED*static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ParseSyntaxTree(string text, Microsoft.CodeAnalysis.ParseOptions options = null, string path = "", System.Text.Encoding encoding = null, System.Collections.Immutable.ImmutableDictionary diagnosticOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.SyntaxTree +*REMOVED*Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.ArgumentList.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax +*REMOVED*Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.Initializer.get -> Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax +*REMOVED*Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.NewKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken +*REMOVED*Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.ArgumentList.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax +*REMOVED*Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.Initializer.get -> Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax +*REMOVED*Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.NewKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken Microsoft.CodeAnalysis.CSharp.Conversion.IsDefaultLiteral.get -> bool Microsoft.CodeAnalysis.CSharp.ForEachStatementInfo.IsAsynchronous.get -> bool Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax.AddBodyAttributeLists(params Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax[] items) -> Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax @@ -20,6 +26,11 @@ Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousMethodExpressionSyntax.AddBlockAtt Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousMethodExpressionSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken asyncKeyword, Microsoft.CodeAnalysis.SyntaxToken delegateKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ParameterListSyntax parameterList, Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax block, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expressionBody) -> Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousMethodExpressionSyntax Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousMethodExpressionSyntax.WithExpressionBody(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expressionBody) -> Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousMethodExpressionSyntax Microsoft.CodeAnalysis.CSharp.Syntax.BaseMethodDeclarationSyntax.AddBodyAttributeLists(params Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax[] items) -> Microsoft.CodeAnalysis.CSharp.Syntax.BaseMethodDeclarationSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax.AddArgumentListArguments(params Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax[] items) -> Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax.WithArgumentList(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax.WithInitializer(Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax initializer) -> Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax.WithNewKeyword(Microsoft.CodeAnalysis.SyntaxToken newKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax.AddAttributeLists(params Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax[] items) -> Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax.Update(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken openBraceToken, Microsoft.CodeAnalysis.SyntaxList statements, Microsoft.CodeAnalysis.SyntaxToken closeBraceToken) -> Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax.WithAttributeLists(Microsoft.CodeAnalysis.SyntaxList attributeLists) -> Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax @@ -67,6 +78,12 @@ Microsoft.CodeAnalysis.CSharp.Syntax.GotoStatementSyntax.WithAttributeLists(Micr Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax.AddAttributeLists(params Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax[] items) -> Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax.Update(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken ifKeyword, Microsoft.CodeAnalysis.SyntaxToken openParenToken, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax condition, Microsoft.CodeAnalysis.SyntaxToken closeParenToken, Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax statement, Microsoft.CodeAnalysis.CSharp.Syntax.ElseClauseSyntax else) -> Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax.WithAttributeLists(Microsoft.CodeAnalysis.SyntaxList attributeLists) -> Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.AddArgumentListArguments(params Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax[] items) -> Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken newKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax argumentList, Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax initializer) -> Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.WithArgumentList(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.WithInitializer(Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax initializer) -> Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.WithNewKeyword(Microsoft.CodeAnalysis.SyntaxToken newKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax Microsoft.CodeAnalysis.CSharp.Syntax.LabeledStatementSyntax.AddAttributeLists(params Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax[] items) -> Microsoft.CodeAnalysis.CSharp.Syntax.LabeledStatementSyntax Microsoft.CodeAnalysis.CSharp.Syntax.LabeledStatementSyntax.Update(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken identifier, Microsoft.CodeAnalysis.SyntaxToken colonToken, Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax statement) -> Microsoft.CodeAnalysis.CSharp.Syntax.LabeledStatementSyntax Microsoft.CodeAnalysis.CSharp.Syntax.LabeledStatementSyntax.WithAttributeLists(Microsoft.CodeAnalysis.SyntaxList attributeLists) -> Microsoft.CodeAnalysis.CSharp.Syntax.LabeledStatementSyntax @@ -124,9 +141,14 @@ Microsoft.CodeAnalysis.CSharp.Syntax.WhileStatementSyntax.WithAttributeLists(Mic Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax.AddAttributeLists(params Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax[] items) -> Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax.Update(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken yieldKeyword, Microsoft.CodeAnalysis.SyntaxToken returnOrBreakKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression, Microsoft.CodeAnalysis.SyntaxToken semicolonToken) -> Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax.WithAttributeLists(Microsoft.CodeAnalysis.SyntaxList attributeLists) -> Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax +Microsoft.CodeAnalysis.CSharp.SyntaxKind.ImplicitObjectCreationExpression = 8659 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind abstract Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousFunctionExpressionSyntax.Block.get -> Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax abstract Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousFunctionExpressionSyntax.ExpressionBody.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax +abstract Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax.ArgumentList.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax +abstract Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax.Initializer.get -> Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax +abstract Microsoft.CodeAnalysis.CSharp.Syntax.BaseObjectCreationExpressionSyntax.NewKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken abstract Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList +override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitImplicitObjectCreationExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax node) -> Microsoft.CodeAnalysis.SyntaxNode override Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousMethodExpressionSyntax.Block.get -> Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax override Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousMethodExpressionSyntax.ExpressionBody.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax override Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList @@ -142,10 +164,18 @@ override Microsoft.CodeAnalysis.CSharp.Syntax.ForEachVariableStatementSyntax.Att override Microsoft.CodeAnalysis.CSharp.Syntax.ForStatementSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList override Microsoft.CodeAnalysis.CSharp.Syntax.GotoStatementSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList override Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList +override Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor visitor) -> void +override Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor visitor) -> TResult +override Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.ArgumentList.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax +override Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.Initializer.get -> Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax +override Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax.NewKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken override Microsoft.CodeAnalysis.CSharp.Syntax.LabeledStatementSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList override Microsoft.CodeAnalysis.CSharp.Syntax.LocalDeclarationStatementSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList override Microsoft.CodeAnalysis.CSharp.Syntax.LocalFunctionStatementSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList override Microsoft.CodeAnalysis.CSharp.Syntax.LockStatementSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList +override Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.ArgumentList.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax +override Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.Initializer.get -> Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax +override Microsoft.CodeAnalysis.CSharp.Syntax.ObjectCreationExpressionSyntax.NewKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken override Microsoft.CodeAnalysis.CSharp.Syntax.ParenthesizedLambdaExpressionSyntax.Block.get -> Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax override Microsoft.CodeAnalysis.CSharp.Syntax.ParenthesizedLambdaExpressionSyntax.ExpressionBody.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax override Microsoft.CodeAnalysis.CSharp.Syntax.ReturnStatementSyntax.AttributeLists.get -> Microsoft.CodeAnalysis.SyntaxList @@ -191,6 +221,9 @@ static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.GotoStatement(Microsoft.CodeA static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.GotoStatement(Microsoft.CodeAnalysis.CSharp.SyntaxKind kind, Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken gotoKeyword, Microsoft.CodeAnalysis.SyntaxToken caseOrDefaultKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression, Microsoft.CodeAnalysis.SyntaxToken semicolonToken) -> Microsoft.CodeAnalysis.CSharp.Syntax.GotoStatementSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.IfStatement(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax condition, Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax statement, Microsoft.CodeAnalysis.CSharp.Syntax.ElseClauseSyntax else) -> Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.IfStatement(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken ifKeyword, Microsoft.CodeAnalysis.SyntaxToken openParenToken, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax condition, Microsoft.CodeAnalysis.SyntaxToken closeParenToken, Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax statement, Microsoft.CodeAnalysis.CSharp.Syntax.ElseClauseSyntax else) -> Microsoft.CodeAnalysis.CSharp.Syntax.IfStatementSyntax +static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ImplicitObjectCreationExpression() -> Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax +static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ImplicitObjectCreationExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax argumentList, Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax initializer) -> Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax +static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ImplicitObjectCreationExpression(Microsoft.CodeAnalysis.SyntaxToken newKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax argumentList, Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax initializer) -> Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.LabeledStatement(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken identifier, Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax statement) -> Microsoft.CodeAnalysis.CSharp.Syntax.LabeledStatementSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.LabeledStatement(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken identifier, Microsoft.CodeAnalysis.SyntaxToken colonToken, Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax statement) -> Microsoft.CodeAnalysis.CSharp.Syntax.LabeledStatementSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.LocalDeclarationStatement(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken awaitKeyword, Microsoft.CodeAnalysis.SyntaxToken usingKeyword, Microsoft.CodeAnalysis.SyntaxTokenList modifiers, Microsoft.CodeAnalysis.CSharp.Syntax.VariableDeclarationSyntax declaration, Microsoft.CodeAnalysis.SyntaxToken semicolonToken) -> Microsoft.CodeAnalysis.CSharp.Syntax.LocalDeclarationStatementSyntax @@ -224,3 +257,5 @@ static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.WhileStatement(Microsoft.Code static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.WhileStatement(Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken whileKeyword, Microsoft.CodeAnalysis.SyntaxToken openParenToken, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax condition, Microsoft.CodeAnalysis.SyntaxToken closeParenToken, Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax statement) -> Microsoft.CodeAnalysis.CSharp.Syntax.WhileStatementSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.YieldStatement(Microsoft.CodeAnalysis.CSharp.SyntaxKind kind, Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.YieldStatement(Microsoft.CodeAnalysis.CSharp.SyntaxKind kind, Microsoft.CodeAnalysis.SyntaxList attributeLists, Microsoft.CodeAnalysis.SyntaxToken yieldKeyword, Microsoft.CodeAnalysis.SyntaxToken returnOrBreakKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression, Microsoft.CodeAnalysis.SyntaxToken semicolonToken) -> Microsoft.CodeAnalysis.CSharp.Syntax.YieldStatementSyntax +virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitImplicitObjectCreationExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax node) -> void +virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitImplicitObjectCreationExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ImplicitObjectCreationExpressionSyntax node) -> TResult From 6a10fcef59763413d1b22cc0b54fabf5b1539f03 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 27 Feb 2020 12:26:24 +0330 Subject: [PATCH 40/41] Revert nullable enable --- src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs index 77bbbf056adb6..e10725077c95a 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs @@ -223,7 +223,6 @@ private BoundExpression BindObjectCreationExpression(BoundUnconvertedObjectCreat } } -#nullable enable /// /// Rewrite the expressions in the switch expression arms to add a conversion to the destination type. /// From 4961ff1fc40c2b2b48b406439e3df2c67b709a66 Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Thu, 27 Feb 2020 12:28:33 +0330 Subject: [PATCH 41/41] Argument list is not optional in new() --- .../Portable/Generated/CSharp.Generated.g4 | 2 +- .../Syntax.xml.Internal.Generated.cs | 46 ++++++++----------- .../Generated/Syntax.xml.Main.Generated.cs | 11 +++-- .../Generated/Syntax.xml.Syntax.Generated.cs | 16 +++---- .../CSharp/Portable/Syntax/Syntax.xml | 2 +- .../Generated/Syntax.Test.xml.Generated.cs | 8 ++-- 6 files changed, 36 insertions(+), 49 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4 b/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4 index 75a903bf7baf3..75272dfaed0b0 100644 --- a/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4 +++ b/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4 @@ -708,7 +708,7 @@ base_object_creation_expression ; implicit_object_creation_expression - : 'new' argument_list? initializer_expression? + : 'new' argument_list initializer_expression? ; object_creation_expression diff --git a/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Internal.Generated.cs b/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Internal.Generated.cs index d51831b1e064c..251046621315d 100644 --- a/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Internal.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Internal.Generated.cs @@ -6266,20 +6266,17 @@ protected BaseObjectCreationExpressionSyntax(ObjectReader reader) internal sealed partial class ImplicitObjectCreationExpressionSyntax : BaseObjectCreationExpressionSyntax { internal readonly SyntaxToken newKeyword; - internal readonly ArgumentListSyntax? argumentList; + internal readonly ArgumentListSyntax argumentList; internal readonly InitializerExpressionSyntax? initializer; - internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken newKeyword, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations) + internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken newKeyword, ArgumentListSyntax argumentList, InitializerExpressionSyntax? initializer, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations) : base(kind, diagnostics, annotations) { this.SlotCount = 3; this.AdjustFlagsAndWidth(newKeyword); this.newKeyword = newKeyword; - if (argumentList != null) - { - this.AdjustFlagsAndWidth(argumentList); - this.argumentList = argumentList; - } + this.AdjustFlagsAndWidth(argumentList); + this.argumentList = argumentList; if (initializer != null) { this.AdjustFlagsAndWidth(initializer); @@ -6287,18 +6284,15 @@ internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken new } } - internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken newKeyword, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer, SyntaxFactoryContext context) + internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken newKeyword, ArgumentListSyntax argumentList, InitializerExpressionSyntax? initializer, SyntaxFactoryContext context) : base(kind) { this.SetFactoryContext(context); this.SlotCount = 3; this.AdjustFlagsAndWidth(newKeyword); this.newKeyword = newKeyword; - if (argumentList != null) - { - this.AdjustFlagsAndWidth(argumentList); - this.argumentList = argumentList; - } + this.AdjustFlagsAndWidth(argumentList); + this.argumentList = argumentList; if (initializer != null) { this.AdjustFlagsAndWidth(initializer); @@ -6306,17 +6300,14 @@ internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken new } } - internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken newKeyword, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer) + internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken newKeyword, ArgumentListSyntax argumentList, InitializerExpressionSyntax? initializer) : base(kind) { this.SlotCount = 3; this.AdjustFlagsAndWidth(newKeyword); this.newKeyword = newKeyword; - if (argumentList != null) - { - this.AdjustFlagsAndWidth(argumentList); - this.argumentList = argumentList; - } + this.AdjustFlagsAndWidth(argumentList); + this.argumentList = argumentList; if (initializer != null) { this.AdjustFlagsAndWidth(initializer); @@ -6327,7 +6318,7 @@ internal ImplicitObjectCreationExpressionSyntax(SyntaxKind kind, SyntaxToken new /// SyntaxToken representing the new keyword. public override SyntaxToken NewKeyword => this.newKeyword; /// ArgumentListSyntax representing the list of arguments passed as part of the object creation expression. - public override ArgumentListSyntax? ArgumentList => this.argumentList; + public override ArgumentListSyntax ArgumentList => this.argumentList; /// InitializerExpressionSyntax representing the initializer expression for the object being created. public override InitializerExpressionSyntax? Initializer => this.initializer; @@ -6375,12 +6366,9 @@ internal ImplicitObjectCreationExpressionSyntax(ObjectReader reader) var newKeyword = (SyntaxToken)reader.ReadValue(); AdjustFlagsAndWidth(newKeyword); this.newKeyword = newKeyword; - var argumentList = (ArgumentListSyntax?)reader.ReadValue(); - if (argumentList != null) - { - AdjustFlagsAndWidth(argumentList); - this.argumentList = argumentList; - } + var argumentList = (ArgumentListSyntax)reader.ReadValue(); + AdjustFlagsAndWidth(argumentList); + this.argumentList = argumentList; var initializer = (InitializerExpressionSyntax?)reader.ReadValue(); if (initializer != null) { @@ -33355,11 +33343,12 @@ public InitializerExpressionSyntax InitializerExpression(SyntaxKind kind, Syntax return result; } - public ImplicitObjectCreationExpressionSyntax ImplicitObjectCreationExpression(SyntaxToken newKeyword, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer) + public ImplicitObjectCreationExpressionSyntax ImplicitObjectCreationExpression(SyntaxToken newKeyword, ArgumentListSyntax argumentList, InitializerExpressionSyntax? initializer) { #if DEBUG if (newKeyword == null) throw new ArgumentNullException(nameof(newKeyword)); if (newKeyword.Kind != SyntaxKind.NewKeyword) throw new ArgumentException(nameof(newKeyword)); + if (argumentList == null) throw new ArgumentNullException(nameof(argumentList)); #endif int hash; @@ -37899,11 +37888,12 @@ public static InitializerExpressionSyntax InitializerExpression(SyntaxKind kind, return result; } - public static ImplicitObjectCreationExpressionSyntax ImplicitObjectCreationExpression(SyntaxToken newKeyword, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer) + public static ImplicitObjectCreationExpressionSyntax ImplicitObjectCreationExpression(SyntaxToken newKeyword, ArgumentListSyntax argumentList, InitializerExpressionSyntax? initializer) { #if DEBUG if (newKeyword == null) throw new ArgumentNullException(nameof(newKeyword)); if (newKeyword.Kind != SyntaxKind.NewKeyword) throw new ArgumentException(nameof(newKeyword)); + if (argumentList == null) throw new ArgumentNullException(nameof(argumentList)); #endif int hash; diff --git a/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Main.Generated.cs b/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Main.Generated.cs index 66920032abd35..ac7127776b223 100644 --- a/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Main.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Main.Generated.cs @@ -1469,7 +1469,7 @@ public partial class CSharpSyntaxRewriter : CSharpSyntaxVisitor => node.Update(VisitToken(node.OpenBraceToken), VisitList(node.Expressions), VisitToken(node.CloseBraceToken)); public override SyntaxNode? VisitImplicitObjectCreationExpression(ImplicitObjectCreationExpressionSyntax node) - => node.Update(VisitToken(node.NewKeyword), (ArgumentListSyntax?)Visit(node.ArgumentList), (InitializerExpressionSyntax?)Visit(node.Initializer)); + => node.Update(VisitToken(node.NewKeyword), (ArgumentListSyntax?)Visit(node.ArgumentList) ?? throw new ArgumentNullException("argumentList"), (InitializerExpressionSyntax?)Visit(node.Initializer)); public override SyntaxNode? VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) => node.Update(VisitToken(node.NewKeyword), (TypeSyntax?)Visit(node.Type) ?? throw new ArgumentNullException("type"), (ArgumentListSyntax?)Visit(node.ArgumentList), (InitializerExpressionSyntax?)Visit(node.Initializer)); @@ -2935,19 +2935,20 @@ public static InitializerExpressionSyntax InitializerExpression(SyntaxKind kind, => SyntaxFactory.InitializerExpression(kind, SyntaxFactory.Token(SyntaxKind.OpenBraceToken), expressions, SyntaxFactory.Token(SyntaxKind.CloseBraceToken)); /// Creates a new ImplicitObjectCreationExpressionSyntax instance. - public static ImplicitObjectCreationExpressionSyntax ImplicitObjectCreationExpression(SyntaxToken newKeyword, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer) + public static ImplicitObjectCreationExpressionSyntax ImplicitObjectCreationExpression(SyntaxToken newKeyword, ArgumentListSyntax argumentList, InitializerExpressionSyntax? initializer) { if (newKeyword.Kind() != SyntaxKind.NewKeyword) throw new ArgumentException(nameof(newKeyword)); - return (ImplicitObjectCreationExpressionSyntax)Syntax.InternalSyntax.SyntaxFactory.ImplicitObjectCreationExpression((Syntax.InternalSyntax.SyntaxToken)newKeyword.Node!, argumentList == null ? null : (Syntax.InternalSyntax.ArgumentListSyntax)argumentList.Green, initializer == null ? null : (Syntax.InternalSyntax.InitializerExpressionSyntax)initializer.Green).CreateRed(); + if (argumentList == null) throw new ArgumentNullException(nameof(argumentList)); + return (ImplicitObjectCreationExpressionSyntax)Syntax.InternalSyntax.SyntaxFactory.ImplicitObjectCreationExpression((Syntax.InternalSyntax.SyntaxToken)newKeyword.Node!, (Syntax.InternalSyntax.ArgumentListSyntax)argumentList.Green, initializer == null ? null : (Syntax.InternalSyntax.InitializerExpressionSyntax)initializer.Green).CreateRed(); } /// Creates a new ImplicitObjectCreationExpressionSyntax instance. - public static ImplicitObjectCreationExpressionSyntax ImplicitObjectCreationExpression(ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer) + public static ImplicitObjectCreationExpressionSyntax ImplicitObjectCreationExpression(ArgumentListSyntax argumentList, InitializerExpressionSyntax? initializer) => SyntaxFactory.ImplicitObjectCreationExpression(SyntaxFactory.Token(SyntaxKind.NewKeyword), argumentList, initializer); /// Creates a new ImplicitObjectCreationExpressionSyntax instance. public static ImplicitObjectCreationExpressionSyntax ImplicitObjectCreationExpression() - => SyntaxFactory.ImplicitObjectCreationExpression(SyntaxFactory.Token(SyntaxKind.NewKeyword), default, default); + => SyntaxFactory.ImplicitObjectCreationExpression(SyntaxFactory.Token(SyntaxKind.NewKeyword), SyntaxFactory.ArgumentList(), default); /// Creates a new ObjectCreationExpressionSyntax instance. public static ObjectCreationExpressionSyntax ObjectCreationExpression(SyntaxToken newKeyword, TypeSyntax type, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer) diff --git a/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Syntax.Generated.cs b/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Syntax.Generated.cs index 3e5dc17ac77d7..81986fa205bd3 100644 --- a/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Syntax.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/Syntax.xml.Syntax.Generated.cs @@ -2734,7 +2734,7 @@ internal ImplicitObjectCreationExpressionSyntax(InternalSyntax.CSharpSyntaxNode public override SyntaxToken NewKeyword => new SyntaxToken(this, ((Syntax.InternalSyntax.ImplicitObjectCreationExpressionSyntax)this.Green).newKeyword, Position, 0); /// ArgumentListSyntax representing the list of arguments passed as part of the object creation expression. - public override ArgumentListSyntax? ArgumentList => GetRed(ref this.argumentList, 1); + public override ArgumentListSyntax ArgumentList => GetRed(ref this.argumentList, 1)!; /// InitializerExpressionSyntax representing the initializer expression for the object being created. public override InitializerExpressionSyntax? Initializer => GetRed(ref this.initializer, 2); @@ -2742,7 +2742,7 @@ internal ImplicitObjectCreationExpressionSyntax(InternalSyntax.CSharpSyntaxNode internal override SyntaxNode? GetNodeSlot(int index) => index switch { - 1 => GetRed(ref this.argumentList, 1), + 1 => GetRed(ref this.argumentList, 1)!, 2 => GetRed(ref this.initializer, 2), _ => null, }; @@ -2758,7 +2758,7 @@ internal ImplicitObjectCreationExpressionSyntax(InternalSyntax.CSharpSyntaxNode public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitImplicitObjectCreationExpression(this); public override TResult Accept(CSharpSyntaxVisitor visitor) => visitor.VisitImplicitObjectCreationExpression(this); - public ImplicitObjectCreationExpressionSyntax Update(SyntaxToken newKeyword, ArgumentListSyntax? argumentList, InitializerExpressionSyntax? initializer) + public ImplicitObjectCreationExpressionSyntax Update(SyntaxToken newKeyword, ArgumentListSyntax argumentList, InitializerExpressionSyntax? initializer) { if (newKeyword != this.NewKeyword || argumentList != this.ArgumentList || initializer != this.Initializer) { @@ -2772,17 +2772,13 @@ public ImplicitObjectCreationExpressionSyntax Update(SyntaxToken newKeyword, Arg internal override BaseObjectCreationExpressionSyntax WithNewKeywordCore(SyntaxToken newKeyword) => WithNewKeyword(newKeyword); public new ImplicitObjectCreationExpressionSyntax WithNewKeyword(SyntaxToken newKeyword) => Update(newKeyword, this.ArgumentList, this.Initializer); - internal override BaseObjectCreationExpressionSyntax WithArgumentListCore(ArgumentListSyntax? argumentList) => WithArgumentList(argumentList); - public new ImplicitObjectCreationExpressionSyntax WithArgumentList(ArgumentListSyntax? argumentList) => Update(this.NewKeyword, argumentList, this.Initializer); + internal override BaseObjectCreationExpressionSyntax WithArgumentListCore(ArgumentListSyntax? argumentList) => WithArgumentList(argumentList ?? throw new ArgumentNullException(nameof(argumentList))); + public new ImplicitObjectCreationExpressionSyntax WithArgumentList(ArgumentListSyntax argumentList) => Update(this.NewKeyword, argumentList, this.Initializer); internal override BaseObjectCreationExpressionSyntax WithInitializerCore(InitializerExpressionSyntax? initializer) => WithInitializer(initializer); public new ImplicitObjectCreationExpressionSyntax WithInitializer(InitializerExpressionSyntax? initializer) => Update(this.NewKeyword, this.ArgumentList, initializer); internal override BaseObjectCreationExpressionSyntax AddArgumentListArgumentsCore(params ArgumentSyntax[] items) => AddArgumentListArguments(items); - public new ImplicitObjectCreationExpressionSyntax AddArgumentListArguments(params ArgumentSyntax[] items) - { - var argumentList = this.ArgumentList ?? SyntaxFactory.ArgumentList(); - return WithArgumentList(argumentList.WithArguments(argumentList.Arguments.AddRange(items))); - } + public new ImplicitObjectCreationExpressionSyntax AddArgumentListArguments(params ArgumentSyntax[] items) => WithArgumentList(this.ArgumentList.WithArguments(this.ArgumentList.Arguments.AddRange(items))); } /// Class which represents the syntax node for object creation expression. diff --git a/src/Compilers/CSharp/Portable/Syntax/Syntax.xml b/src/Compilers/CSharp/Portable/Syntax/Syntax.xml index c203f8076a215..9eec0189ed36a 100644 --- a/src/Compilers/CSharp/Portable/Syntax/Syntax.xml +++ b/src/Compilers/CSharp/Portable/Syntax/Syntax.xml @@ -1456,7 +1456,7 @@ SyntaxToken representing the new keyword. - + ArgumentListSyntax representing the list of arguments passed as part of the object creation expression. diff --git a/src/Compilers/CSharp/Test/Syntax/Generated/Syntax.Test.xml.Generated.cs b/src/Compilers/CSharp/Test/Syntax/Generated/Syntax.Test.xml.Generated.cs index 93c4800d53e21..ac23339faf342 100644 --- a/src/Compilers/CSharp/Test/Syntax/Generated/Syntax.Test.xml.Generated.cs +++ b/src/Compilers/CSharp/Test/Syntax/Generated/Syntax.Test.xml.Generated.cs @@ -164,7 +164,7 @@ private static Syntax.InternalSyntax.InitializerExpressionSyntax GenerateInitial => InternalSyntaxFactory.InitializerExpression(SyntaxKind.ObjectInitializerExpression, InternalSyntaxFactory.Token(SyntaxKind.OpenBraceToken), new Microsoft.CodeAnalysis.Syntax.InternalSyntax.SeparatedSyntaxList(), InternalSyntaxFactory.Token(SyntaxKind.CloseBraceToken)); private static Syntax.InternalSyntax.ImplicitObjectCreationExpressionSyntax GenerateImplicitObjectCreationExpression() - => InternalSyntaxFactory.ImplicitObjectCreationExpression(InternalSyntaxFactory.Token(SyntaxKind.NewKeyword), null, null); + => InternalSyntaxFactory.ImplicitObjectCreationExpression(InternalSyntaxFactory.Token(SyntaxKind.NewKeyword), GenerateArgumentList(), null); private static Syntax.InternalSyntax.ObjectCreationExpressionSyntax GenerateObjectCreationExpression() => InternalSyntaxFactory.ObjectCreationExpression(InternalSyntaxFactory.Token(SyntaxKind.NewKeyword), GenerateIdentifierName(), null, null); @@ -1266,7 +1266,7 @@ public void TestImplicitObjectCreationExpressionFactoryAndProperties() var node = GenerateImplicitObjectCreationExpression(); Assert.Equal(SyntaxKind.NewKeyword, node.NewKeyword.Kind); - Assert.Null(node.ArgumentList); + Assert.NotNull(node.ArgumentList); Assert.Null(node.Initializer); AttachAndCheckDiagnostics(node); @@ -9212,7 +9212,7 @@ private static InitializerExpressionSyntax GenerateInitializerExpression() => SyntaxFactory.InitializerExpression(SyntaxKind.ObjectInitializerExpression, SyntaxFactory.Token(SyntaxKind.OpenBraceToken), new SeparatedSyntaxList(), SyntaxFactory.Token(SyntaxKind.CloseBraceToken)); private static ImplicitObjectCreationExpressionSyntax GenerateImplicitObjectCreationExpression() - => SyntaxFactory.ImplicitObjectCreationExpression(SyntaxFactory.Token(SyntaxKind.NewKeyword), default(ArgumentListSyntax), default(InitializerExpressionSyntax)); + => SyntaxFactory.ImplicitObjectCreationExpression(SyntaxFactory.Token(SyntaxKind.NewKeyword), GenerateArgumentList(), default(InitializerExpressionSyntax)); private static ObjectCreationExpressionSyntax GenerateObjectCreationExpression() => SyntaxFactory.ObjectCreationExpression(SyntaxFactory.Token(SyntaxKind.NewKeyword), GenerateIdentifierName(), default(ArgumentListSyntax), default(InitializerExpressionSyntax)); @@ -10314,7 +10314,7 @@ public void TestImplicitObjectCreationExpressionFactoryAndProperties() var node = GenerateImplicitObjectCreationExpression(); Assert.Equal(SyntaxKind.NewKeyword, node.NewKeyword.Kind()); - Assert.Null(node.ArgumentList); + Assert.NotNull(node.ArgumentList); Assert.Null(node.Initializer); var newNode = node.WithNewKeyword(node.NewKeyword).WithArgumentList(node.ArgumentList).WithInitializer(node.Initializer); Assert.Equal(node, newNode);