@@ -745,11 +745,17 @@ static bool validateParameterType(ParamDecl *decl, DeclContext *DC,
745
745
auto elementOptions = (options |
746
746
(decl->isVariadic () ? TR_VariadicFunctionInput
747
747
: TR_FunctionInput));
748
- bool hadError = TC.validateType (decl->getTypeLoc (), DC,
749
- elementOptions, resolver);
750
-
748
+ bool hadError = false ;
749
+
750
+ // We might have a null typeLoc if this is a closure parameter list,
751
+ // where parameters are allowed to elide their types.
752
+ if (!decl->getTypeLoc ().isNull ()) {
753
+ hadError |= TC.validateType (decl->getTypeLoc (), DC,
754
+ elementOptions, resolver);
755
+ }
756
+
751
757
Type Ty = decl->getTypeLoc ().getType ();
752
- if (decl->isVariadic () && !hadError) {
758
+ if (decl->isVariadic () && !Ty. isNull () && ! hadError) {
753
759
Ty = TC.getArraySliceType (decl->getStartLoc (), Ty);
754
760
if (Ty.isNull ()) {
755
761
hadError = true ;
@@ -759,7 +765,7 @@ static bool validateParameterType(ParamDecl *decl, DeclContext *DC,
759
765
// If the param is not a 'let' and it is not an 'inout'.
760
766
// It must be a 'var'. Provide helpful diagnostics like a shadow copy
761
767
// in the function body to fix the 'var' attribute.
762
- if (!decl->isLet () && !Ty->is <InOutType>() && !hadError) {
768
+ if (!decl->isLet () && (Ty. isNull () || !Ty->is <InOutType>() ) && !hadError) {
763
769
auto func = dyn_cast_or_null<AbstractFunctionDecl>(DC);
764
770
diagnoseAndMigrateVarParameterToBody (decl, func, TC);
765
771
decl->setInvalid ();
@@ -768,7 +774,7 @@ static bool validateParameterType(ParamDecl *decl, DeclContext *DC,
768
774
769
775
if (hadError)
770
776
decl->getTypeLoc ().setType (ErrorType::get (TC.Context ), /* validated*/ true );
771
-
777
+
772
778
return hadError;
773
779
}
774
780
@@ -779,8 +785,7 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL, DeclContext *DC,
779
785
bool hadError = false ;
780
786
781
787
for (auto param : *PL) {
782
- if (param->getTypeLoc ().getTypeRepr ())
783
- hadError |= validateParameterType (param, DC, options, resolver, *this );
788
+ hadError |= validateParameterType (param, DC, options, resolver, *this );
784
789
785
790
auto type = param->getTypeLoc ().getType ();
786
791
if (!type && param->hasType ()) {
0 commit comments