Skip to content

Commit 24fa750

Browse files
Merge pull request swiftlang#31927 from AnthonyLatsis/assert-type-param-3
GenericSignatureImpl, swiftlang#31712: Plug remaining relevant methods with type param. assertions
2 parents b8c74b4 + b25c466 commit 24fa750

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
329329
/// Determine whether the given dependent type is equal to a concrete type.
330330
bool isConcreteType(Type type) const;
331331

332-
/// Return the concrete type that the given dependent type is constrained to,
332+
/// Return the concrete type that the given type parameter is constrained to,
333333
/// or the null Type if it is not the subject of a concrete same-type
334334
/// constraint.
335335
Type getConcreteType(Type type) const;
336336

337-
/// Return the layout constraint that the given dependent type is constrained
337+
/// Return the layout constraint that the given type parameter is constrained
338338
/// to, or the null LayoutConstraint if it is not the subject of layout
339339
/// constraint.
340340
LayoutConstraint getLayoutConstraint(Type type) const;

lib/AST/GenericSignature.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Type GenericSignatureImpl::getSuperclassBound(Type type) const {
428428
/// required to conform.
429429
GenericSignature::RequiredProtocols
430430
GenericSignatureImpl::getRequiredProtocols(Type type) const {
431-
if (!type->isTypeParameter()) return { };
431+
assert(type->isTypeParameter() && "Expected a type parameter");
432432

433433
auto &builder = *getGenericSignatureBuilder();
434434
auto equivClass =
@@ -479,11 +479,11 @@ bool GenericSignatureImpl::isConcreteType(Type type) const {
479479
return bool(getConcreteType(type));
480480
}
481481

482-
/// Return the concrete type that the given dependent type is constrained to,
482+
/// Return the concrete type that the given type parameter is constrained to,
483483
/// or the null Type if it is not the subject of a concrete same-type
484484
/// constraint.
485485
Type GenericSignatureImpl::getConcreteType(Type type) const {
486-
if (!type->isTypeParameter()) return Type();
486+
assert(type->isTypeParameter() && "Expected a type parameter");
487487

488488
auto &builder = *getGenericSignatureBuilder();
489489
auto equivClass =
@@ -496,7 +496,8 @@ Type GenericSignatureImpl::getConcreteType(Type type) const {
496496
}
497497

498498
LayoutConstraint GenericSignatureImpl::getLayoutConstraint(Type type) const {
499-
if (!type->isTypeParameter()) return LayoutConstraint();
499+
assert(type->isTypeParameter() &&
500+
"Only type parameters can have layout constraints");
500501

501502
auto &builder = *getGenericSignatureBuilder();
502503
auto equivClass =

lib/AST/SubstitutionMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ Type SubstitutionMap::lookupSubstitution(CanSubstitutableType type) const {
271271

272272
// The generic parameter may have been made concrete by the generic signature,
273273
// substitute into the concrete type.
274-
if (auto concreteType = genericSig->getConcreteType(genericParam)){
274+
if (auto concreteType = genericSig->getConcreteType(genericParam)) {
275275
// Set the replacement type to an error, to block infinite recursion.
276276
replacementType = ErrorType::get(concreteType);
277277

0 commit comments

Comments
 (0)