Skip to content

Commit 5df9933

Browse files
committed
[AST] Enforce non-null type for value GenericTypeParamType
Make sure we have a value type for a value generic parameter.
1 parent 3daae59 commit 5df9933

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

lib/AST/Type.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,8 @@ GenericTypeParamType::GenericTypeParamType(GenericTypeParamKind paramKind,
21532153
const ASTContext &ctx)
21542154
: SubstitutableType(TypeKind::GenericTypeParam, &ctx, props),
21552155
Decl(nullptr) {
2156+
ASSERT(!(paramKind == GenericTypeParamKind::Value && !valueType) &&
2157+
"Value generic parameter must have type");
21562158
IsDecl = false;
21572159
Depth = depth;
21582160
Weight = weight;

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,7 @@ namespace {
17461746

17471747
Type visitTypeValueExpr(TypeValueExpr *E) {
17481748
auto ty = E->getParamDecl()->getValueType();
1749-
if (!ty || ty->hasError())
1749+
if (ty->hasError())
17501750
return recordInvalidNode(E);
17511751
return ty;
17521752
}

lib/Sema/TypeCheckType.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,9 @@ namespace {
811811
// If either value type has an error, we've already diagnosed the issue.
812812
auto paramValueTy = paramType->getValueType();
813813
auto secondValueTy = secondType->getValueType();
814-
if (!paramValueTy || paramValueTy->hasError() ||
815-
!secondValueTy || secondValueTy->hasError()) {
814+
if (paramValueTy->hasError() || secondValueTy->hasError())
816815
return true;
817-
}
816+
818817
// Otherwise, these are both value parameters and check that both their
819818
// value types are the same.
820819
return paramValueTy->isEqual(secondValueTy);

0 commit comments

Comments
 (0)