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

Debug assertion failure in MethodSymbol.AsMember when called from NullableWalker.GetNullableOfTValueSlot #73182

Closed
sharwell opened this issue Apr 22, 2024 · 3 comments

Comments

@sharwell
Copy link
Member

sharwell commented Apr 22, 2024

MethodSymbol.AsMember assumes that the newOwner is not an error symbol. This can fail (cause a debug assertion) for the following caller:

valueProperty = getValue?.AsMember((NamedTypeSymbol)containingType)?.AssociatedSymbol;

It seems like it may be sufficient to add the following check to GetNullableOfTValueSlot, however this would potentially impact additional call sites:

if (containingType.IsErrorType())
{
    valueProperty = null;
    return -1;
}
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 22, 2024
@jaredpar jaredpar added Bug Tenet-Acquisition User cannot successfully acquire/install the product in some situation. These are often setup bugs. New Language Feature - Nullable Reference Types Nullable Reference Types and removed untriaged Issues and PRs which have not yet been triaged by a lead Tenet-Acquisition User cannot successfully acquire/install the product in some situation. These are often setup bugs. labels Apr 22, 2024
@jaredpar jaredpar added this to the 17.11 milestone Apr 22, 2024
@RikkiGibson
Copy link
Contributor

It would be useful to know more specifically what triggers the failure. For example, a unit test which triggers the assertion through use of public APIs.

@sharwell
Copy link
Member Author

@RikkiGibson I'm not sure what the trigger is. It appeared randomly in an experimental instance where Compilers.slnf was open. This one would typically occur shortly after opening a solution that restored documents that were open when the IDE closed.

@jjonescz
Copy link
Contributor

jjonescz commented May 3, 2024

I cannot reproduce this. And I don't see how the debug assert in AsMember could fail:

  1. I assume this is about Debug.Assert(ReferenceEquals(newOwner.OriginalDefinition, this.ContainingSymbol.OriginalDefinition));
  2. In GetNullableOfTValueSlot, we have already asserted Debug.Assert(containingType.IsNullableType());, i.e., containingType.OriginalDefinition must be the symbol System.Nullable<T>.
  3. So when we call AsMember((NamedTypeSymbol)containingType), the newOwner.OriginalDefinition must be the symbol System.Nullable<T> and hence it will be equal to this.ContainingSymbol.OriginalDefinition (where this is the symbol for SpecialMember.System_Nullable_T_get_Value).

MethodSymbol.AsMember assumes that the newOwner is not an error symbol.

In general, I don't think AsMember minds error symbols. It mostly just calls new SubstitutedMethodSymbol which specifically handles error symbols in some asserts.

@jjonescz jjonescz closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants