Skip to content

Commit cd62d52

Browse files
committed
Parse attributes on generic type parameter declarations and check availability.
1 parent 1c781f8 commit cd62d52

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

lib/Parse/ParseGeneric.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,22 @@ ParserResult<GenericParamList> Parser::parseGenericParameters(SourceLoc LAngleLo
4343
SmallVector<GenericTypeParamDecl *, 4> GenericParams;
4444
bool Invalid = false;
4545
do {
46+
// Note that we're parsing a declaration.
47+
StructureMarkerRAII ParsingDecl(*this, Tok.getLoc(),
48+
StructureMarkerKind::Declaration);
49+
50+
// Parse attributes.
51+
DeclAttributes attributes;
52+
if (Tok.hasComment())
53+
attributes.add(new (Context) RawDocCommentAttr(Tok.getCommentRange()));
54+
bool foundCCTokenInAttr;
55+
parseDeclAttributeList(attributes, foundCCTokenInAttr);
56+
4657
// Parse the name of the parameter.
4758
Identifier Name;
4859
SourceLoc NameLoc;
49-
if (parseIdentifier(Name, NameLoc, diag::expected_generics_parameter_name)) {
60+
if (parseIdentifier(Name, NameLoc,
61+
diag::expected_generics_parameter_name)) {
5062
Invalid = true;
5163
break;
5264
}
@@ -83,6 +95,9 @@ ParserResult<GenericParamList> Parser::parseGenericParameters(SourceLoc LAngleLo
8395
Param->setInherited(Context.AllocateCopy(Inherited));
8496
GenericParams.push_back(Param);
8597

98+
// Attach attributes.
99+
Param->getAttrs() = attributes;
100+
86101
// Add this parameter to the scope.
87102
addToScope(Param);
88103

lib/Sema/TypeCheckType.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,15 @@ static bool diagnoseAvailability(Type ty, IdentTypeRepr *IdType, SourceLoc Loc,
11711171
return true;
11721172
}
11731173

1174+
if (auto *GPT = dyn_cast<GenericTypeParamType>(ty.getPointer())) {
1175+
if (auto GP = GPT->getDecl()) {
1176+
if (checkTypeDeclAvailability(GP, IdType, Loc, DC, TC,
1177+
AllowPotentiallyUnavailableProtocol)) {
1178+
return true;
1179+
}
1180+
}
1181+
}
1182+
11741183
// Look through substituted types to diagnose when the original
11751184
// type is marked unavailable.
11761185
if (auto *ST = dyn_cast<SubstitutedType>(ty.getPointer())) {

test/attr/attr_availability.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,7 @@ func OutputStreamTest(message: String, inout to: OutputStreamType) {
200200
print(message, &to) // expected-error {{'print' is unavailable: Please use the 'toStream' label for the target stream: 'print((...), toStream: &...)'}}
201201
}
202202

203+
// expected-note@+1{{'T' has been explicitly marked unavailable here}}
204+
struct UnavailableGenericParam<@available(*, unavailable, message="nope") T> {
205+
func f(t: T) { } // expected-error{{'T' is unavailable: nope}}
206+
}

0 commit comments

Comments
 (0)