Skip to content

Commit a4bfa3f

Browse files
authored
Merge pull request #82275 from slavapestov/more-fuzzer-fixes-2
More fuzzer fixes
2 parents e29b425 + 1b4178f commit a4bfa3f

26 files changed

+108
-61
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,10 +1436,10 @@ ERROR(did_not_call_function_value,none,
14361436
())
14371437
ERROR(did_not_call_function,none,
14381438
"function %0 was used as a property; add () to call it",
1439-
(Identifier))
1439+
(DeclBaseName))
14401440
ERROR(did_not_call_method,none,
14411441
"method %0 was used as a property; add () to call it",
1442-
(Identifier))
1442+
(DeclBaseName))
14431443

14441444
ERROR(init_not_instance_member_use_assignment,none,
14451445
"'init' is a member of the type; use assignment "
@@ -3781,9 +3781,6 @@ ERROR(enum_non_integer_convertible_raw_type_no_value,none,
37813781
"expressible by integer or string literal", ())
37823782
ERROR(enum_raw_value_not_unique,none,
37833783
"raw value for enum case is not unique", ())
3784-
ERROR(enum_raw_value_magic_literal,none,
3785-
"use of '%0' literal as raw value for enum case is not supported",
3786-
(StringRef))
37873784
NOTE(enum_raw_value_used_here,none,
37883785
"raw value previously used here", ())
37893786
NOTE(enum_raw_value_incrementing_from_here,none,

lib/AST/ASTScope.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ SourceRange NominalTypeScope::getBraces() const { return decl->getBraces(); }
356356

357357
NullablePtr<NominalTypeDecl>
358358
ExtensionScope::getCorrespondingNominalTypeDecl() const {
359+
if (!decl->hasBeenBound())
360+
return nullptr;
359361
return decl->getExtendedNominal();
360362
}
361363

lib/AST/ProtocolConformance.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,9 +990,12 @@ static bool isVanishingTupleConformance(
990990

991991
auto replacementTypes = substitutions.getReplacementTypes();
992992
assert(replacementTypes.size() == 1);
993-
auto packType = replacementTypes[0]->castTo<PackType>();
994993

995-
return (packType->getNumElements() == 1 &&
994+
// This might not be an actual pack type with an invalid tuple conformance.
995+
auto packType = replacementTypes[0]->getAs<PackType>();
996+
997+
return (packType &&
998+
packType->getNumElements() == 1 &&
996999
!packType->getElementTypes()[0]->is<PackExpansionType>());
9971000
}
9981001

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ static void desugarSameShapeRequirement(
451451
!req.getSecondType()->isParameterPack()) {
452452
errors.push_back(RequirementError::forInvalidShapeRequirement(
453453
req, loc));
454+
return;
454455
}
455456

456457
result.emplace_back(RequirementKind::SameShape,

lib/Parse/ParseDecl.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6337,8 +6337,8 @@ ParserStatus Parser::parseDecl(bool IsAtStartOfLineOrPreviousHadSemi,
63376337
DescriptiveKind = DescriptiveDeclKind::StaticProperty;
63386338
break;
63396339
case StaticSpellingKind::KeywordClass:
6340-
llvm_unreachable("kw_class is only parsed as a modifier if it's "
6341-
"followed by a keyword");
6340+
DescriptiveKind = DescriptiveDeclKind::ClassProperty;
6341+
break;
63426342
}
63436343

63446344
diagnose(Tok.getLoc(), diag::expected_keyword_in_decl, "var",
@@ -6366,8 +6366,7 @@ ParserStatus Parser::parseDecl(bool IsAtStartOfLineOrPreviousHadSemi,
63666366
DescriptiveKind = DescriptiveDeclKind::StaticMethod;
63676367
break;
63686368
case StaticSpellingKind::KeywordClass:
6369-
llvm_unreachable("kw_class is only parsed as a modifier if it's "
6370-
"followed by a keyword");
6369+
DescriptiveKind = DescriptiveDeclKind::ClassMethod;
63716370
}
63726371
}
63736372

@@ -9229,6 +9228,20 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
92299228
return DCC.fixupParserResult(Status, ED);
92309229
}
92319230

9231+
static bool isValidEnumRawValueLiteral(LiteralExpr *expr) {
9232+
if (expr == nullptr)
9233+
return false;
9234+
9235+
if (!isa<IntegerLiteralExpr>(expr) &&
9236+
!isa<FloatLiteralExpr>(expr) &&
9237+
!isa<StringLiteralExpr>(expr) &&
9238+
!isa<BooleanLiteralExpr>(expr) &&
9239+
!isa<NilLiteralExpr>(expr))
9240+
return false;
9241+
9242+
return true;
9243+
}
9244+
92329245
/// Parse a 'case' of an enum.
92339246
///
92349247
/// \verbatim
@@ -9346,8 +9359,7 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags,
93469359
}
93479360
// The raw value must be syntactically a simple literal.
93489361
LiteralRawValueExpr = dyn_cast<LiteralExpr>(RawValueExpr.getPtrOrNull());
9349-
if (!LiteralRawValueExpr
9350-
|| isa<InterpolatedStringLiteralExpr>(LiteralRawValueExpr)) {
9362+
if (!isValidEnumRawValueLiteral(LiteralRawValueExpr)) {
93519363
diagnose(RawValueExpr.getPtrOrNull()->getLoc(),
93529364
diag::nonliteral_enum_case_raw_value);
93539365
LiteralRawValueExpr = nullptr;

lib/Sema/CSDiagnostics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3940,22 +3940,22 @@ bool MissingCallFailure::diagnoseAsError() {
39403940

39413941
if (auto *DRE = getAsExpr<DeclRefExpr>(anchor)) {
39423942
emitDiagnostic(diag::did_not_call_function,
3943-
DRE->getDecl()->getBaseIdentifier())
3943+
DRE->getDecl()->getBaseName())
39443944
.fixItInsertAfter(insertLoc, "()");
39453945
return true;
39463946
}
39473947

39483948
if (auto *UDE = getAsExpr<UnresolvedDotExpr>(anchor)) {
39493949
emitDiagnostic(diag::did_not_call_method,
3950-
UDE->getName().getBaseIdentifier())
3950+
UDE->getName().getBaseName())
39513951
.fixItInsertAfter(insertLoc, "()");
39523952
return true;
39533953
}
39543954

39553955
if (auto *DSCE = getAsExpr<DotSyntaxCallExpr>(anchor)) {
39563956
if (auto *DRE = dyn_cast<DeclRefExpr>(DSCE->getFn())) {
39573957
emitDiagnostic(diag::did_not_call_method,
3958-
DRE->getDecl()->getBaseIdentifier())
3958+
DRE->getDecl()->getBaseName())
39593959
.fixItInsertAfter(insertLoc, "()");
39603960
return true;
39613961
}

lib/Sema/DerivedConformance/DerivedConformance.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ void DerivedConformance::diagnoseIfSynthesisUnsupportedForDecl(
272272
shouldDiagnose = !isa<EnumDecl>(nominal);
273273
}
274274

275+
if (isa<BuiltinTupleDecl>(nominal))
276+
shouldDiagnose = false;
277+
275278
if (shouldDiagnose) {
276279
auto &ctx = nominal->getASTContext();
277280
ctx.Diags.diagnose(nominal->getLoc(),

lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6268,9 +6268,9 @@ diagnoseDictionaryLiteralDuplicateKeyEntries(const Expr *E,
62686268
note.fixItRemove(duplicated.first->getSourceRange());
62696269
if (duplicatedEltIdx < commanLocs.size()) {
62706270
note.fixItRemove(commanLocs[duplicatedEltIdx]);
6271-
} else {
6271+
} else if (!commanLocs.empty()) {
62726272
// For the last element remove the previous comma.
6273-
note.fixItRemove(commanLocs[duplicatedEltIdx - 1]);
6273+
note.fixItRemove(commanLocs[commanLocs.size() - 1]);
62746274
}
62756275
};
62766276

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,15 +1304,6 @@ EnumRawValuesRequest::evaluate(Evaluator &eval, EnumDecl *ED,
13041304
SourceLoc diagLoc = uncheckedRawValueOf(elt)->isImplicit()
13051305
? elt->getLoc()
13061306
: uncheckedRawValueOf(elt)->getLoc();
1307-
if (auto magicLiteralExpr =
1308-
dyn_cast<MagicIdentifierLiteralExpr>(prevValue)) {
1309-
auto kindString =
1310-
magicLiteralExpr->getKindString(magicLiteralExpr->getKind());
1311-
Diags.diagnose(diagLoc, diag::enum_raw_value_magic_literal, kindString);
1312-
elt->setInvalid();
1313-
continue;
1314-
}
1315-
13161307
// Check that the raw value is unique.
13171308
RawValueKey key{prevValue};
13181309
RawValueSource source{elt, lastExplicitValueElt};

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ bool swift::isOverrideBasedOnType(const ValueDecl *decl, Type declTy,
217217
return false;
218218
}
219219

220+
if (declTy->is<ErrorType>())
221+
return false;
222+
220223
auto fnType1 = declTy->castTo<AnyFunctionType>();
221224
auto fnType2 = parentDeclTy->castTo<AnyFunctionType>();
222225
return AnyFunctionType::equalParams(fnType1->getParams(),

0 commit comments

Comments
 (0)