Sema: Stop checking @main if no decl synthesized. #36529
Merged
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.
When requestifying the synthesis of the main function for the type annotated @main via SynthesizeMainFunctionRequest, what previously were bailouts from AttributeChecker::visitMainTypeAttr had to become returns of nullptr from SynthesizeMainFunctionRequest::evaluate. Consequently, AttributeChecker::visitMainTypeAttr must check whether synthesis actually succeeded before proceeding to to register the main decl for a file.
In simple illegal cases, not checking happened to work because SourceFile::registerMainDecl would return early if the decl being registered was the same as the already registered main decl and in particular if the decl being registered was nullptr and the previously registered one was nullptr as well. When, however, there are multiple types annotated @main, if a function is successfully synthesized for one type but synthesis fails for the second, an attempt will be made to register nullptr as the main decl and will move past the check at the beginning of SourceFile::registerMainDecl, resulting in a crash.
Here, we bail from AttributeChecker::visitMainTypeAttr if function synthesis fails and add an assert to SourceFile::registerMainDecl that the provided decl is non-null.
rdar://75547146