Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow fully oblivious types to coexist with nullable-aware base types in partial classes #55861

Merged
merged 7 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,36 @@ private Tuple<NamedTypeSymbol, ImmutableArray<NamedTypeSymbol>> MakeDeclaredBase
baseType = partBase;
baseTypeLocation = decl.NameLocation;
}
else if ((object)partBase != null && !TypeSymbol.Equals(partBase, baseType, TypeCompareKind.ConsiderEverything2) && partBase.TypeKind != TypeKind.Error)
else if ((object)partBase != null && !TypeSymbol.Equals(partBase, baseType, TypeCompareKind.ConsiderEverything) && partBase.TypeKind != TypeKind.Error)
{
// the parts do not agree
if (partBase.Equals(baseType, TypeCompareKind.ObliviousNullableModifierMatchesAny))
{
if (containsOnlyOblivious(baseType))
{
baseType = partBase;
baseTypeLocation = decl.NameLocation;
continue;
}
else if (containsOnlyOblivious(partBase))
{
continue;
}
}

var info = diagnostics.Add(ErrorCode.ERR_PartialMultipleBases, Locations[0], this);
baseType = new ExtendedErrorTypeSymbol(baseType, LookupResultKind.Ambiguous, info);
baseTypeLocation = decl.NameLocation;
reportedPartialConflict = true;

static bool containsOnlyOblivious(TypeSymbol type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we tend to put local functions at the end of methods. Consider moving to keep main logic flow

{
return TypeWithAnnotations.Create(type).VisitType(
type: null,
static (type, arg, flag) => !type.Type.IsValueType && !type.NullableAnnotation.IsOblivious(),
typePredicate: null,
arg: (object)null) is null;
}
}
}

Expand Down
Loading