Skip to content

Commit d203856

Browse files
committed
Allow checking for invalid @main
Changing the overload resolution behavior results in the ordering that `main` and `$main` are typechecked. If there is an error in parsing or sema before we have typechecked these two functions, we get weird errors about `$main` calling the main-actor `main` function being invalid. This is because we have already set the `@main` attribute to invalid, so we don't recognize the `$main` context as being a main entrypoint. The error message compounds to making a confusing situation worse given that `$main` is implicit. So by ignoring the failed `@main` attribute, we still annotate the `$main` and `main` function as being on the main actor, so everyone is happy in that respect. To get the nasty behavior, you can forget to pass `-parse-as-library` with this commit removed.
1 parent 1b419c9 commit d203856

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3695,7 +3695,8 @@ getActorIsolationForMainFuncDecl(FuncDecl *fnDecl) {
36953695
if (!declContext)
36963696
return {};
36973697
const bool isMainDeclContext =
3698-
declContext->getAttrs().hasAttribute<MainTypeAttr>();
3698+
declContext->getAttrs().hasAttribute<MainTypeAttr>(
3699+
/*allow invalid*/ true);
36993700

37003701
ASTContext &ctx = fnDecl->getASTContext();
37013702

0 commit comments

Comments
 (0)