@@ -744,11 +744,11 @@ static bool validateTypedPattern(TypeChecker &TC,
744
744
return hadError;
745
745
}
746
746
747
- static bool validateParameterType (ParamDecl *decl, TypeResolution resolution,
747
+ static void validateParameterType (ParamDecl *decl, TypeResolution resolution,
748
748
TypeResolutionOptions options,
749
- TypeChecker &TC ) {
749
+ ASTContext &ctx ) {
750
750
if (auto ty = decl->getTypeLoc ().getType ())
751
- return ty-> hasError () ;
751
+ return ;
752
752
753
753
auto origContext = options.getContext ();
754
754
options.setContext (None);
@@ -761,35 +761,25 @@ static bool validateParameterType(ParamDecl *decl, TypeResolution resolution,
761
761
TypeResolverContext::FunctionInput);
762
762
options |= TypeResolutionFlags::Direct;
763
763
764
- bool hadError = false ;
765
-
766
764
auto &TL = decl->getTypeLoc ();
767
765
768
- // We might have a null typeLoc if this is a closure parameter list,
769
- // where parameters are allowed to elide their types.
770
- if (!TL.isNull ()) {
771
- hadError |= TypeChecker::validateType (TC.Context , TL, resolution, options);
772
- }
766
+ TypeChecker::validateType (ctx, TL, resolution, options);
773
767
774
768
Type Ty = TL.getType ();
775
- if (decl->isVariadic () && !Ty. isNull () && !hadError ) {
776
- Ty = TC. getArraySliceType (decl->getStartLoc (), Ty);
769
+ if (decl->isVariadic ()) {
770
+ Ty = TypeChecker:: getArraySliceType (decl->getStartLoc (), Ty);
777
771
if (Ty.isNull ()) {
778
- hadError = true ;
772
+ Ty = ErrorType::get (ctx) ;
779
773
}
780
- TL.setType (Ty);
781
774
782
775
// Disallow variadic parameters in enum elements.
783
- if (!hadError && origContext == TypeResolverContext::EnumElementDecl) {
784
- TC. diagnose ( decl->getStartLoc (), diag::enum_element_ellipsis);
785
- hadError = true ;
776
+ if (origContext == TypeResolverContext::EnumElementDecl) {
777
+ decl->diagnose ( diag::enum_element_ellipsis);
778
+ Ty = ErrorType::get (ctx) ;
786
779
}
787
- }
788
-
789
- if (hadError)
790
- TL.setInvalidType (TC.Context );
791
780
792
- return hadError;
781
+ TL.setType (Ty);
782
+ }
793
783
}
794
784
795
785
// / Type check a parameter list.
@@ -802,60 +792,43 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL,
802
792
803
793
for (auto param : *PL) {
804
794
auto typeRepr = param->getTypeLoc ().getTypeRepr ();
805
- if (!typeRepr &&
806
- param->hasInterfaceType ()) {
807
- hadError |= param->isInvalid ();
795
+ if (!typeRepr) {
796
+ if ( param->hasInterfaceType ())
797
+ hadError |= param->isInvalid ();
808
798
continue ;
809
799
}
810
800
811
- hadError |= validateParameterType (param, resolution, options, * this );
801
+ validateParameterType (param, resolution, options, Context );
812
802
813
803
auto type = param->getTypeLoc ().getType ();
804
+ param->setInterfaceType (type);
814
805
815
- // If there was no type specified, and if we're not looking at a
816
- // ClosureExpr, then we have a parse error (no type was specified). The
817
- // parser will have already diagnosed this, but treat this as a type error
818
- // as well to get the ParamDecl marked invalid and to get an ErrorType.
819
- if (!type) {
820
- // Closure argument lists are allowed to be missing types.
821
- if (options.isAnyExpr ())
822
- continue ;
823
- param->setInvalid ();
824
- }
825
-
826
- if (param->isInvalid () || type->hasError ()) {
827
- param->markInvalid ();
828
- hadError = true ;
829
- } else {
830
- param->setInterfaceType (type);
831
- }
806
+ hadError |= param->isInvalid ();
832
807
833
- if (!hadError) {
834
- auto *nestedRepr = typeRepr;
835
-
836
- // Look through parens here; other than parens, specifiers
837
- // must appear at the top level of a parameter type.
838
- while (auto *tupleRepr = dyn_cast<TupleTypeRepr>(nestedRepr)) {
839
- if (!tupleRepr->isParenType ())
840
- break ;
841
- nestedRepr = tupleRepr->getElementType (0 );
842
- }
808
+ auto *nestedRepr = typeRepr;
843
809
844
- if (isa<InOutTypeRepr>(nestedRepr)) {
845
- param->setSpecifier (ParamDecl::Specifier::InOut);
846
- } else if (isa<SharedTypeRepr>(nestedRepr)) {
847
- param->setSpecifier (ParamDecl::Specifier::Shared);
848
- } else if (isa<OwnedTypeRepr>(nestedRepr)) {
849
- param->setSpecifier (ParamDecl::Specifier::Owned);
850
- }
810
+ // Look through parens here; other than parens, specifiers
811
+ // must appear at the top level of a parameter type.
812
+ while (auto *tupleRepr = dyn_cast<TupleTypeRepr>(nestedRepr)) {
813
+ if (!tupleRepr->isParenType ())
814
+ break ;
815
+ nestedRepr = tupleRepr->getElementType (0 );
816
+ }
817
+
818
+ if (isa<InOutTypeRepr>(nestedRepr)) {
819
+ param->setSpecifier (ParamDecl::Specifier::InOut);
820
+ } else if (isa<SharedTypeRepr>(nestedRepr)) {
821
+ param->setSpecifier (ParamDecl::Specifier::Shared);
822
+ } else if (isa<OwnedTypeRepr>(nestedRepr)) {
823
+ param->setSpecifier (ParamDecl::Specifier::Owned);
851
824
}
852
825
853
- if (param->isInOut () && param->isDefaultArgument ()) {
826
+ if (isa<InOutTypeRepr>(nestedRepr) &&
827
+ param->isDefaultArgument ()) {
854
828
diagnose (param->getDefaultValue ()->getLoc (),
855
829
swift::diag::cannot_provide_default_value_inout,
856
830
param->getName ());
857
- param->markInvalid ();
858
- hadError = true ;
831
+ param->setSpecifier (ParamDecl::Specifier::Default);
859
832
}
860
833
}
861
834
0 commit comments