Don't dereference a null type when building a template argument name#732
Merged
tannergooding merged 1 commit intoJul 13, 2026
Merged
Conversation
GetCursorQualifiedName builds a qualified name for a class template specialization by appending each template argument. For a Type-kind argument it did templateArgument.AsType.AsString, but AsType is null when the argument's underlying type maps to an invalid CXType (an unsupported type the shim can't represent), so GetOrCreate<Type> returns null and the deref throws a NullReferenceException during generation. Guard the access and fall back to the same '?' placeholder already used for other unsupported argument kinds. The success path is byte-identical. Fixes dotnet#580 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #580.
Generation crashes with a
NullReferenceExceptionwhile building the qualified name of a class template specialization:Root cause.
AppendTemplateArgumenthandles aType-kind argument withtemplateArgument.AsType.AsString.AsTyperoutes throughTranslationUnit.GetOrCreate<Type>, which returnsnullfor aCXType_Invalidhandle (theDebug.Assertguarding that path is compiled out of Release). So when an argument's underlyingQualTypemaps to an invalidCXType— an unsupported/exotic type the shim can't represent, as happens deep in thesol2/spdlog/ C++20 template instantiations from the report —AsTypeisnulland.AsStringthrows.AsIntegralreturns alongand thedefaultbranch is already safe, so this is the only unguarded deref.Fix. Guard the access and fall back to the same
'?'placeholder thedefaultbranch already uses for unsupported argument kinds:The success path is byte-identical (non-null
AsTypestill yieldsAsType.AsString); the only new behavior is that a previously-fatal NRE now renders asFoo<?>in the qualified name (used for diagnostics and remapping keys), matching how unsupported kinds already render.On testing. I verified the mechanism directly from source and confirmed it's the only null-deref in the method. I could not build a minimal standalone repro — the invalid-
CXTypeargument only arises from the specific deeply-nested standard-library instantiations in the original report, which need the full ModEngine2 + sol2 + spdlog include tree and toolchain to stand up. This mirrors the earlierharden generator against malformed inputschange, which likewise guards a native-only crash path that isn't expressible through the golden-file harness. Full suite green with zero golden changes.Note
This PR description and the code change were drafted by Copilot on my behalf.