Files
swift-mirror/validation-test/compiler_crashers_2_fixed/rdar75547146.swift
Nate Chandler 6c5d62c011 Sema: Stop checking @main if no decl synthesized.
When requestifying the synthesis of the main function for the type
annotated @main via SynthesizeMainFunctionRequest, what were 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 cases, this 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
2021-03-19 16:54:16 -07:00

11 lines
153 B
Swift

// RUN: not %target-swift-frontend %s -c -parse-as-library
@main struct M1 {
static func main() {}
}
@main struct M2<T> {
static func main() {}
}