Skip to content

Commit 8dfce14

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 7c65ed2 commit 8dfce14

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
@@ -3380,7 +3380,8 @@ getActorIsolationForMainFuncDecl(FuncDecl *fnDecl) {
33803380
if (!declContext)
33813381
return {};
33823382
const bool isMainDeclContext =
3383-
declContext->getAttrs().hasAttribute<MainTypeAttr>();
3383+
declContext->getAttrs().hasAttribute<MainTypeAttr>(
3384+
/*allow invalid*/ true);
33843385

33853386
ASTContext &ctx = fnDecl->getASTContext();
33863387

0 commit comments

Comments
 (0)