Skip to content

Commit 7b33254

Browse files
author
Nathan Hawes
authored
Merge pull request #28226 from nathawes/assertion-fixes
Fix some SourceKit assertion hits
2 parents c0c247e + 43523df commit 7b33254

15 files changed

+822
-86
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,12 @@ ERROR(invalid_arg_count_for_operator,none,
911911
"operators must have one or two arguments", ())
912912
ERROR(operator_in_local_scope,none,
913913
"operator functions can only be declared at global or in type scope", ())
914-
ERROR(nonstatic_operator_in_type,none,
915-
"operator %0 declared in type %1 must be 'static'", (Identifier, Type))
914+
ERROR(nonstatic_operator_in_nominal,none,
915+
"operator %0 declared in type %1 must be 'static'",
916+
(Identifier, DeclName))
917+
ERROR(nonstatic_operator_in_extension,none,
918+
"operator %0 declared in extension of %1 must be 'static'",
919+
(Identifier, TypeRepr*))
916920
ERROR(nonfinal_operator_in_class,none,
917921
"operator %0 declared in non-final class %1 must be 'final'",
918922
(Identifier, Type))

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,15 +2866,6 @@ class Verifier : public ASTWalker {
28662866

28672867
void verifyParsed(ConstructorDecl *CD) {
28682868
PrettyStackTraceDecl debugStack("verifying ConstructorDecl", CD);
2869-
2870-
auto *DC = CD->getDeclContext();
2871-
if (!isa<NominalTypeDecl>(DC) && !isa<ExtensionDecl>(DC) &&
2872-
!CD->isInvalid()) {
2873-
Out << "ConstructorDecls outside nominal types and extensions "
2874-
"should be marked invalid";
2875-
abort();
2876-
}
2877-
28782869
verifyParsedBase(CD);
28792870
}
28802871

@@ -2955,15 +2946,6 @@ class Verifier : public ASTWalker {
29552946
Out << "DestructorDecl cannot be generic";
29562947
abort();
29572948
}
2958-
2959-
auto *DC = DD->getDeclContext();
2960-
if (!isa<NominalTypeDecl>(DC) && !isa<ExtensionDecl>(DC) &&
2961-
!DD->isInvalid()) {
2962-
Out << "DestructorDecls outside nominal types and extensions "
2963-
"should be marked invalid";
2964-
abort();
2965-
}
2966-
29672949
verifyParsedBase(DD);
29682950
}
29692951

lib/IDE/SyntaxModel.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,6 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) {
904904
pushStructureNode(SN, NTD);
905905

906906
} else if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
907-
// Normally bindExtension() would take care of computing the extended
908-
// nominal. It must be done before asking for generic parameters.
909-
if (!inInactiveClause || ASTScope::areInactiveIfConfigClausesSupported())
910-
ED->computeExtendedNominal();
911907
SyntaxStructureNode SN;
912908
setDecl(SN, D);
913909
SN.Kind = SyntaxStructureKind::Extension;

lib/Sema/TypeCheckDecl.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,10 +1269,18 @@ IsStaticRequest::evaluate(Evaluator &evaluator, FuncDecl *decl) const {
12691269
decl->isOperator() &&
12701270
dc->isTypeContext()) {
12711271
auto operatorName = decl->getFullName().getBaseIdentifier();
1272-
decl->diagnose(diag::nonstatic_operator_in_type,
1273-
operatorName, dc->getDeclaredInterfaceType())
1274-
.fixItInsert(decl->getAttributeInsertionLoc(/*forModifier=*/true),
1275-
"static ");
1272+
if (auto ED = dyn_cast<ExtensionDecl>(dc->getAsDecl())) {
1273+
decl->diagnose(diag::nonstatic_operator_in_extension,
1274+
operatorName, ED->getExtendedTypeRepr())
1275+
.fixItInsert(decl->getAttributeInsertionLoc(/*forModifier=*/true),
1276+
"static ");
1277+
} else {
1278+
auto *NTD = cast<NominalTypeDecl>(dc->getAsDecl());
1279+
decl->diagnose(diag::nonstatic_operator_in_nominal, operatorName,
1280+
NTD->getName())
1281+
.fixItInsert(decl->getAttributeInsertionLoc(/*forModifier=*/true),
1282+
"static ");
1283+
}
12761284
result = true;
12771285
}
12781286

test/SourceKit/DocumentStructure/Inputs/main.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,33 @@ class OneMore {
135135
fatalError()
136136
}
137137
}
138+
139+
class Chain<A> {
140+
func + (lhs: Chain<A>, rhs: Chain<A>) -> Chain<A> { fatalError() }
141+
}
142+
143+
public init() {
144+
fatalError()
145+
}
146+
147+
deinit {
148+
fatalError()
149+
}
150+
151+
#if false
152+
extension Result {
153+
func foo() {}
154+
}
155+
156+
extension Outer {
157+
class Inner {
158+
deinit {}
159+
}
160+
}
161+
162+
public extension Outer2 {
163+
class Inner2 {
164+
deinit {}
165+
}
166+
}
167+
#endif

test/SourceKit/DocumentStructure/access_parse.swift.response

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,6 @@
777777
},
778778
{
779779
key.kind: source.lang.swift.decl.extension,
780-
key.accessibility: source.lang.swift.accessibility.internal,
781780
key.name: "DefAccess",
782781
key.offset: 1399,
783782
key.length: 43,
@@ -788,7 +787,6 @@
788787
key.substructure: [
789788
{
790789
key.kind: source.lang.swift.decl.function.method.instance,
791-
key.accessibility: source.lang.swift.accessibility.internal,
792790
key.name: "defFunc()",
793791
key.offset: 1423,
794792
key.length: 17,
@@ -801,7 +799,6 @@
801799
},
802800
{
803801
key.kind: source.lang.swift.decl.extension,
804-
key.accessibility: source.lang.swift.accessibility.internal,
805802
key.name: "PubAccess",
806803
key.offset: 1443,
807804
key.length: 43,
@@ -812,7 +809,6 @@
812809
key.substructure: [
813810
{
814811
key.kind: source.lang.swift.decl.function.method.instance,
815-
key.accessibility: source.lang.swift.accessibility.internal,
816812
key.name: "defFunc()",
817813
key.offset: 1467,
818814
key.length: 17,
@@ -825,7 +821,6 @@
825821
},
826822
{
827823
key.kind: source.lang.swift.decl.extension,
828-
key.accessibility: source.lang.swift.accessibility.internal,
829824
key.name: "IntAccess",
830825
key.offset: 1487,
831826
key.length: 43,
@@ -836,7 +831,6 @@
836831
key.substructure: [
837832
{
838833
key.kind: source.lang.swift.decl.function.method.instance,
839-
key.accessibility: source.lang.swift.accessibility.internal,
840834
key.name: "defFunc()",
841835
key.offset: 1511,
842836
key.length: 17,
@@ -849,7 +843,6 @@
849843
},
850844
{
851845
key.kind: source.lang.swift.decl.extension,
852-
key.accessibility: source.lang.swift.accessibility.internal,
853846
key.name: "PrivAccess",
854847
key.offset: 1531,
855848
key.length: 44,
@@ -860,7 +853,6 @@
860853
key.substructure: [
861854
{
862855
key.kind: source.lang.swift.decl.function.method.instance,
863-
key.accessibility: source.lang.swift.accessibility.internal,
864856
key.name: "defFunc()",
865857
key.offset: 1556,
866858
key.length: 17,

0 commit comments

Comments
 (0)