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