@@ -130,37 +130,6 @@ Parser::parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
130
130
Inherited.push_back ({Ty.get ()});
131
131
}
132
132
133
- // Parse the '=' followed by a type.
134
- TypeLoc DefaultType;
135
-
136
- if (Context.LangOpts .hasFeature (Feature::DefaultGenerics)) {
137
- // TODO: Don't allow defaults for values or parameter packs at the moment.
138
- if (Tok.is (tok::equal) && !EachLoc.isValid () && !LetLoc.isValid ()) {
139
- (void )consumeToken ();
140
- ParserResult<TypeRepr> Ty;
141
-
142
- if (Tok.isAny (tok::identifier, tok::code_complete, tok::kw_protocol,
143
- tok::kw_Any) || Tok.isTilde ()) {
144
- Ty = parseType ();
145
- } else if (Tok.is (tok::kw_class)) {
146
- diagnose (Tok, diag::unexpected_class_constraint);
147
- diagnose (Tok, diag::suggest_anyobject)
148
- .fixItReplace (Tok.getLoc (), " AnyObject" );
149
- consumeToken ();
150
- Result.setIsParseError ();
151
- } else {
152
- diagnose (Tok, diag::expected_generics_type_restriction, Name);
153
- Result.setIsParseError ();
154
- }
155
-
156
- if (Ty.hasCodeCompletion ())
157
- return makeParserCodeCompletionStatus ();
158
-
159
- if (Ty.isNonNull ())
160
- DefaultType = Ty.get ();
161
- }
162
- }
163
-
164
133
auto ParamKind = GenericTypeParamKind::Type;
165
134
SourceLoc SpecifierLoc;
166
135
@@ -172,8 +141,22 @@ Parser::parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
172
141
SpecifierLoc = LetLoc;
173
142
}
174
143
144
+ // Parse the '=' followed by a type.
145
+ ParserResult<TypeRepr> DefaultType;
146
+
147
+ if (Context.LangOpts .hasFeature (Feature::DefaultGenerics)) {
148
+ // TODO: Don't allow defaults for values or parameter packs at the moment.
149
+ if (Tok.is (tok::equal) && ParamKind == GenericTypeParamKind::Type) {
150
+ consumeToken (tok::equal);
151
+ DefaultType = parseType (diag::expected_type);
152
+ Result |= DefaultType;
153
+ if (DefaultType.isNull ())
154
+ return Result;
155
+ }
156
+ }
157
+
175
158
auto *Param = GenericTypeParamDecl::createParsed (
176
- CurDeclContext, Name, NameLoc, SpecifierLoc, DefaultType,
159
+ CurDeclContext, Name, NameLoc, SpecifierLoc, DefaultType. getPtrOrNull () ,
177
160
/* index*/ GenericParams.size (), ParamKind);
178
161
if (!Inherited.empty ())
179
162
Param->setInherited (Context.AllocateCopy (Inherited));
0 commit comments