Skip to content

Commit

Permalink
feat: Ignores declare field as nullable on structs
Browse files Browse the repository at this point in the history
  • Loading branch information
ironcev committed Jun 13, 2019
1 parent f22bc99 commit 4ded7f5
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ bool NullableContextCanBeEnabledForIdentifier((ISymbol symbol, SyntaxNode declar
return false;

var typeSymbol = GetTypeSymbol();
// WARNING: A bit paranoid but still. Never remove this check because
// the GetSuggestion() later on assumes that the type symbol exists.
if (typeSymbol == null) return false;

// For this, we want to have a special suggestion
Expand Down Expand Up @@ -198,9 +200,16 @@ variableDeclarator.Parent is VariableDeclarationSyntax variableDeclaration &&

ISharpenSuggestion GetSuggestion(ISymbol symbol)
{
// The type surely exists at this point on all the symbols.
switch (symbol)
{
case IFieldSymbol _: return EnableNullableContextAndDeclareFieldAsNullable.Instance;
case IFieldSymbol fieldSymbol:
if (fieldSymbol.Type.IsReferenceType)
return EnableNullableContextAndDeclareFieldAsNullable.Instance;
// TODO-IG: Just ignoring structs so far.
// They are rarely used anyway compared to classes.
// Still, see what to do with structs.
return null;
case IPropertySymbol _: return EnableNullableContextAndDeclareReferencePropertyAsNullable.Instance;
case IParameterSymbol _: return EnableNullableContextAndDeclareReferenceParameterAsNullable.Instance;
case ILocalSymbol _: return EnableNullableContextAndDeclareReferenceVariableAsNullable.Instance;
Expand Down

0 comments on commit 4ded7f5

Please sign in to comment.