@@ -130,37 +130,6 @@ Parser::parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
130130 Inherited.push_back ({Ty.get ()});
131131 }
132132
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-
164133 auto ParamKind = GenericTypeParamKind::Type;
165134 SourceLoc SpecifierLoc;
166135
@@ -172,8 +141,22 @@ Parser::parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
172141 SpecifierLoc = LetLoc;
173142 }
174143
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+
175158 auto *Param = GenericTypeParamDecl::createParsed (
176- CurDeclContext, Name, NameLoc, SpecifierLoc, DefaultType,
159+ CurDeclContext, Name, NameLoc, SpecifierLoc, DefaultType. getPtrOrNull () ,
177160 /* index*/ GenericParams.size (), ParamKind);
178161 if (!Inherited.empty ())
179162 Param->setInherited (Context.AllocateCopy (Inherited));
0 commit comments