@@ -725,9 +725,8 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
725725 // Make sure we have the right number of generic arguments.
726726 // FIXME: If we have fewer arguments than we need, that might be okay, if
727727 // we're allowed to deduce the remaining arguments from context.
728- auto genericDecl = cast<GenericTypeDecl>(decl);
729728 auto genericArgs = generic->getGenericArgs ();
730- auto genericParams = genericDecl ->getGenericParams ();
729+ auto genericParams = decl ->getGenericParams ();
731730 if (genericParams->size () != genericArgs.size ()) {
732731 if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
733732 diags.diagnose (loc, diag::type_parameter_count_mismatch, decl->getName (),
@@ -756,10 +755,10 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
756755 }
757756
758757 // FIXME: More principled handling of circularity.
759- if (!genericDecl ->getGenericSignature ()) {
758+ if (!decl ->getGenericSignature ()) {
760759 diags.diagnose (loc, diag::recursive_decl_reference,
761- genericDecl ->getDescriptiveKind (), genericDecl ->getName ());
762- genericDecl ->diagnose (diag::kind_declared_here, DescriptiveDeclKind::Type);
760+ decl ->getDescriptiveKind (), decl ->getName ());
761+ decl ->diagnose (diag::kind_declared_here, DescriptiveDeclKind::Type);
763762 return ErrorType::get (ctx);
764763 }
765764
@@ -777,9 +776,8 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
777776 args.push_back (substTy);
778777 }
779778
780- auto result = TypeChecker::applyUnboundGenericArguments (
781- unboundType, genericDecl, loc,
782- resolution, args);
779+ const auto result = TypeChecker::applyUnboundGenericArguments (
780+ decl, unboundType->getParent (), loc, resolution, args);
783781
784782 const auto genericOptions = genericResolution.getOptions ();
785783 if (!genericOptions.contains (TypeResolutionFlags::AllowUnavailable)) {
@@ -802,10 +800,10 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
802800}
803801
804802// / Apply generic arguments to the given type.
805- Type TypeChecker::applyUnboundGenericArguments (
806- UnboundGenericType *unboundType, GenericTypeDecl *decl ,
807- SourceLoc loc, TypeResolution resolution,
808- ArrayRef<Type> genericArgs) {
803+ Type TypeChecker::applyUnboundGenericArguments (GenericTypeDecl *decl,
804+ Type parentTy, SourceLoc loc ,
805+ TypeResolution resolution,
806+ ArrayRef<Type> genericArgs) {
809807 assert (genericArgs.size () == decl->getGenericParams ()->size () &&
810808 " invalid arguments, use applyGenericArguments for diagnostic emitting" );
811809
@@ -826,20 +824,20 @@ Type TypeChecker::applyUnboundGenericArguments(
826824
827825 // Get the substitutions for outer generic parameters from the parent
828826 // type.
829- if (auto parentType = unboundType-> getParent () ) {
830- if (parentType ->hasUnboundGenericType ()) {
827+ if (parentTy ) {
828+ if (parentTy ->hasUnboundGenericType ()) {
831829 // If we're working with a nominal type declaration, just construct
832830 // a bound generic type without checking the generic arguments.
833831 if (auto *nominalDecl = dyn_cast<NominalTypeDecl>(decl)) {
834- return BoundGenericType::get (nominalDecl, parentType , genericArgs);
832+ return BoundGenericType::get (nominalDecl, parentTy , genericArgs);
835833 }
836834
837835 assert (!resultType->hasTypeParameter ());
838836 return resultType;
839837 }
840838
841- subs = parentType ->getContextSubstitutions (decl->getDeclContext ());
842- skipRequirementsCheck |= parentType ->hasTypeVariable ();
839+ subs = parentTy ->getContextSubstitutions (decl->getDeclContext ());
840+ skipRequirementsCheck |= parentTy ->hasTypeVariable ();
843841 } else if (auto genericEnv =
844842 decl->getDeclContext ()->getGenericEnvironmentOfContext ()) {
845843 auto genericSig = genericEnv->getGenericSignature ();
@@ -876,11 +874,11 @@ Type TypeChecker::applyUnboundGenericArguments(
876874
877875 if (!skipRequirementsCheck &&
878876 resolution.getStage () > TypeResolutionStage::Structural) {
879- auto result =
880- checkGenericArguments ( dc, loc, noteLoc, unboundType ,
881- genericSig-> getGenericParams ( ),
882- genericSig->getRequirements (),
883- QueryTypeSubstitutionMap{subs});
877+ auto result = checkGenericArguments (
878+ dc, loc, noteLoc,
879+ UnboundGenericType::get (decl, parentTy, dc-> getASTContext () ),
880+ genericSig-> getGenericParams (), genericSig->getRequirements (),
881+ QueryTypeSubstitutionMap{subs});
884882
885883 switch (result) {
886884 case RequirementCheckResult::Failure:
@@ -903,14 +901,12 @@ Type TypeChecker::applyUnboundGenericArguments(
903901 LookUpConformanceInModule (module ));
904902
905903 // Form a sugared typealias reference.
906- Type parentType = unboundType->getParent ();
907- if (typealias && (!parentType || !parentType->isAnyExistentialType ())) {
904+ if (typealias && (!parentTy || !parentTy->isAnyExistentialType ())) {
908905 auto genericSig = typealias->getGenericSignature ();
909906 auto subMap = SubstitutionMap::get (genericSig,
910907 QueryTypeSubstitutionMap{subs},
911908 LookUpConformanceInModule (module ));
912- resultType = TypeAliasType::get (typealias, parentType,
913- subMap, resultType);
909+ resultType = TypeAliasType::get (typealias, parentTy, subMap, resultType);
914910 }
915911
916912 return resultType;
@@ -3311,17 +3307,16 @@ Type TypeResolver::resolveDictionaryType(DictionaryTypeRepr *repr,
33113307 return ErrorType::get (Context);
33123308 }
33133309
3314- auto dictDecl = Context.getDictionaryDecl ();
3310+ auto * const dictDecl = Context.getDictionaryDecl ();
33153311 if (!dictDecl) {
33163312 Context.Diags .diagnose (repr->getBrackets ().Start ,
33173313 diag::sugar_type_not_found, 3 );
33183314 return ErrorType::get (Context);
33193315 }
33203316
3321- auto unboundTy = dictDecl->getDeclaredType ()->castTo <UnboundGenericType>();
3322- Type args[] = {keyTy, valueTy};
33233317 if (!TypeChecker::applyUnboundGenericArguments (
3324- unboundTy, dictDecl, repr->getStartLoc (), resolution, args)) {
3318+ dictDecl, nullptr , repr->getStartLoc (), resolution,
3319+ {keyTy, valueTy})) {
33253320 assert (Context.Diags .hadAnyError ());
33263321 return ErrorType::get (Context);
33273322 }
0 commit comments