Skip to content

Fix some SourceKit assertion hits #28226

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 4 commits into from
Nov 19, 2019
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
8 changes: 6 additions & 2 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,12 @@ ERROR(invalid_arg_count_for_operator,none,
"operators must have one or two arguments", ())
ERROR(operator_in_local_scope,none,
"operator functions can only be declared at global or in type scope", ())
ERROR(nonstatic_operator_in_type,none,
"operator %0 declared in type %1 must be 'static'", (Identifier, Type))
ERROR(nonstatic_operator_in_nominal,none,
"operator %0 declared in type %1 must be 'static'",
(Identifier, DeclName))
ERROR(nonstatic_operator_in_extension,none,
"operator %0 declared in extension of %1 must be 'static'",
(Identifier, TypeRepr*))
ERROR(nonfinal_operator_in_class,none,
"operator %0 declared in non-final class %1 must be 'final'",
(Identifier, Type))
Expand Down
18 changes: 0 additions & 18 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2866,15 +2866,6 @@ class Verifier : public ASTWalker {

void verifyParsed(ConstructorDecl *CD) {
PrettyStackTraceDecl debugStack("verifying ConstructorDecl", CD);

auto *DC = CD->getDeclContext();
if (!isa<NominalTypeDecl>(DC) && !isa<ExtensionDecl>(DC) &&
!CD->isInvalid()) {
Out << "ConstructorDecls outside nominal types and extensions "
"should be marked invalid";
abort();
}

verifyParsedBase(CD);
}

Expand Down Expand Up @@ -2955,15 +2946,6 @@ class Verifier : public ASTWalker {
Out << "DestructorDecl cannot be generic";
abort();
}

auto *DC = DD->getDeclContext();
if (!isa<NominalTypeDecl>(DC) && !isa<ExtensionDecl>(DC) &&
!DD->isInvalid()) {
Out << "DestructorDecls outside nominal types and extensions "
"should be marked invalid";
abort();
}

verifyParsedBase(DD);
}

Expand Down
4 changes: 0 additions & 4 deletions lib/IDE/SyntaxModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,6 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
pushStructureNode(SN, NTD);

} else if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
// Normally bindExtension() would take care of computing the extended
// nominal. It must be done before asking for generic parameters.
if (!inInactiveClause || ASTScope::areInactiveIfConfigClausesSupported())
ED->computeExtendedNominal();
SyntaxStructureNode SN;
setDecl(SN, D);
SN.Kind = SyntaxStructureKind::Extension;
Expand Down
16 changes: 12 additions & 4 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,10 +1258,18 @@ IsStaticRequest::evaluate(Evaluator &evaluator, FuncDecl *decl) const {
decl->isOperator() &&
dc->isTypeContext()) {
auto operatorName = decl->getFullName().getBaseIdentifier();
decl->diagnose(diag::nonstatic_operator_in_type,
operatorName, dc->getDeclaredInterfaceType())
.fixItInsert(decl->getAttributeInsertionLoc(/*forModifier=*/true),
"static ");
if (auto ED = dyn_cast<ExtensionDecl>(dc->getAsDecl())) {
decl->diagnose(diag::nonstatic_operator_in_extension,
operatorName, ED->getExtendedTypeRepr())
.fixItInsert(decl->getAttributeInsertionLoc(/*forModifier=*/true),
"static ");
} else {
auto *NTD = cast<NominalTypeDecl>(dc->getAsDecl());
decl->diagnose(diag::nonstatic_operator_in_nominal, operatorName,
NTD->getName())
.fixItInsert(decl->getAttributeInsertionLoc(/*forModifier=*/true),
"static ");
}
result = true;
}

Expand Down
30 changes: 30 additions & 0 deletions test/SourceKit/DocumentStructure/Inputs/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,33 @@ class OneMore {
fatalError()
}
}

class Chain<A> {
func + (lhs: Chain<A>, rhs: Chain<A>) -> Chain<A> { fatalError() }
}

public init() {
fatalError()
}

deinit {
fatalError()
}

#if false
extension Result {
func foo() {}
}

extension Outer {
class Inner {
deinit {}
}
}

public extension Outer2 {
class Inner2 {
deinit {}
}
}
#endif
8 changes: 0 additions & 8 deletions test/SourceKit/DocumentStructure/access_parse.swift.response
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,6 @@
},
{
key.kind: source.lang.swift.decl.extension,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "DefAccess",
key.offset: 1399,
key.length: 43,
Expand All @@ -788,7 +787,6 @@
key.substructure: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "defFunc()",
key.offset: 1423,
key.length: 17,
Expand All @@ -801,7 +799,6 @@
},
{
key.kind: source.lang.swift.decl.extension,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "PubAccess",
key.offset: 1443,
key.length: 43,
Expand All @@ -812,7 +809,6 @@
key.substructure: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "defFunc()",
key.offset: 1467,
key.length: 17,
Expand All @@ -825,7 +821,6 @@
},
{
key.kind: source.lang.swift.decl.extension,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "IntAccess",
key.offset: 1487,
key.length: 43,
Expand All @@ -836,7 +831,6 @@
key.substructure: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "defFunc()",
key.offset: 1511,
key.length: 17,
Expand All @@ -849,7 +843,6 @@
},
{
key.kind: source.lang.swift.decl.extension,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "PrivAccess",
key.offset: 1531,
key.length: 44,
Expand All @@ -860,7 +853,6 @@
key.substructure: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "defFunc()",
key.offset: 1556,
key.length: 17,
Expand Down
Loading