You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The anonymous type field in the following should be declared as string rather than string?. Instead, y.ToString() generates a warning that y may be null.
using System.Linq;
class C
{
static void Main()
{
var x = new string[] { "" };
var y = x.Select(s => new { s }).First().s;
y.ToString();
}
}
(jcouv update:)
I also noticed a reference to the feature flag in binding logic for anonymous types, which seems wrong (the feature flag should only affect diagnostics, but not symbols from binding).
private BoundExpression BindAnonymousObjectCreation(AnonymousObjectCreationExpressionSyntaxnode,DiagnosticBagdiagnostics){
...// calculate the expression's type and report errors if needed
TypeSymbol fieldType = GetAnonymousTypeFieldType(boundExpressions[i], fieldInitializer, diagnostics,ref hasError);// build anonymous type field descriptor
fieldSyntaxNodes[i]=(nameToken.Kind()== SyntaxKind.IdentifierToken)?(CSharpSyntaxNode)nameToken.Parent :fieldInitializer;
fields[i]=new AnonymousTypeField(fieldName==null?"$"+ i.ToString():fieldName, fieldSyntaxNodes[i].Location,
TypeSymbolWithAnnotations.Create(fieldType, isNullableIfReferenceType: node.IsFeatureStaticNullCheckingEnabled()));// <===== THIS SEEMS FISHY
...}
The text was updated successfully, but these errors were encountered:
The anonymous type field in the following should be declared as
string
rather thanstring?
. Instead,y.ToString()
generates a warning thaty
may be null.(jcouv update:)
I also noticed a reference to the feature flag in binding logic for anonymous types, which seems wrong (the feature flag should only affect diagnostics, but not symbols from binding).
The text was updated successfully, but these errors were encountered: