Skip to content

[Type checker] Don't finalize decls from other source files after an error #18259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Sema/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
if (decl->isInvalid())
continue;

// If we've already encountered an error, don't finalize declarations
// from other source files.
if (TC.Context.hadError() &&
decl->getDeclContext()->getParentSourceFile() != &SF)
continue;

TC.finalizeDecl(decl);
}

Expand Down
11 changes: 5 additions & 6 deletions test/Sema/Inputs/availability_multi_other.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ class OtherIntroduced10_51 {
return OtherIntroduced10_52()
}

func takes10_52(o: OtherIntroduced10_52) {
func takes10_52(o: OtherIntroduced10_52) {
}
// expected-error@-2{{'OtherIntroduced10_52' is only available on OS X 10.52 or newer}}
// expected-note@-3{{add @available attribute to enclosing instance method}}


@available(OSX, introduced: 10.52)
func takes10_52Introduced10_52(o: OtherIntroduced10_52) {
}

// expected-error@+1{{'OtherIntroduced10_52' is only available on OS X 10.52 or newer}}
var propOf10_52: OtherIntroduced10_52 =
OtherIntroduced10_52()


OtherIntroduced10_52() // We don't expect an error here because the initializer is not type checked (by design).

@available(OSX, introduced: 10.52)
var propOf10_52Introduced10_52: OtherIntroduced10_52 = OtherIntroduced10_52()
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/Inputs/circularity_multifile_error_helper.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct External {
var member: Something // expected-error{{use of undeclared type 'Something'}}
var member: Something
}

struct OtherExternal {}