@@ -725,9 +725,8 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
725
725
// Make sure we have the right number of generic arguments.
726
726
// FIXME: If we have fewer arguments than we need, that might be okay, if
727
727
// we're allowed to deduce the remaining arguments from context.
728
- auto genericDecl = cast<GenericTypeDecl>(decl);
729
728
auto genericArgs = generic->getGenericArgs ();
730
- auto genericParams = genericDecl ->getGenericParams ();
729
+ auto genericParams = decl ->getGenericParams ();
731
730
if (genericParams->size () != genericArgs.size ()) {
732
731
if (!options.contains (TypeResolutionFlags::SilenceErrors)) {
733
732
diags.diagnose (loc, diag::type_parameter_count_mismatch, decl->getName (),
@@ -756,10 +755,10 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
756
755
}
757
756
758
757
// FIXME: More principled handling of circularity.
759
- if (!genericDecl ->getGenericSignature ()) {
758
+ if (!decl ->getGenericSignature ()) {
760
759
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);
763
762
return ErrorType::get (ctx);
764
763
}
765
764
@@ -777,9 +776,8 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
777
776
args.push_back (substTy);
778
777
}
779
778
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);
783
781
784
782
const auto genericOptions = genericResolution.getOptions ();
785
783
if (!genericOptions.contains (TypeResolutionFlags::AllowUnavailable)) {
@@ -802,10 +800,10 @@ static Type applyGenericArguments(Type type, TypeResolution resolution,
802
800
}
803
801
804
802
// / 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) {
809
807
assert (genericArgs.size () == decl->getGenericParams ()->size () &&
810
808
" invalid arguments, use applyGenericArguments for diagnostic emitting" );
811
809
@@ -826,20 +824,20 @@ Type TypeChecker::applyUnboundGenericArguments(
826
824
827
825
// Get the substitutions for outer generic parameters from the parent
828
826
// type.
829
- if (auto parentType = unboundType-> getParent () ) {
830
- if (parentType ->hasUnboundGenericType ()) {
827
+ if (parentTy ) {
828
+ if (parentTy ->hasUnboundGenericType ()) {
831
829
// If we're working with a nominal type declaration, just construct
832
830
// a bound generic type without checking the generic arguments.
833
831
if (auto *nominalDecl = dyn_cast<NominalTypeDecl>(decl)) {
834
- return BoundGenericType::get (nominalDecl, parentType , genericArgs);
832
+ return BoundGenericType::get (nominalDecl, parentTy , genericArgs);
835
833
}
836
834
837
835
assert (!resultType->hasTypeParameter ());
838
836
return resultType;
839
837
}
840
838
841
- subs = parentType ->getContextSubstitutions (decl->getDeclContext ());
842
- skipRequirementsCheck |= parentType ->hasTypeVariable ();
839
+ subs = parentTy ->getContextSubstitutions (decl->getDeclContext ());
840
+ skipRequirementsCheck |= parentTy ->hasTypeVariable ();
843
841
} else if (auto genericEnv =
844
842
decl->getDeclContext ()->getGenericEnvironmentOfContext ()) {
845
843
auto genericSig = genericEnv->getGenericSignature ();
@@ -876,11 +874,11 @@ Type TypeChecker::applyUnboundGenericArguments(
876
874
877
875
if (!skipRequirementsCheck &&
878
876
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});
884
882
885
883
switch (result) {
886
884
case RequirementCheckResult::Failure:
@@ -903,14 +901,12 @@ Type TypeChecker::applyUnboundGenericArguments(
903
901
LookUpConformanceInModule (module ));
904
902
905
903
// Form a sugared typealias reference.
906
- Type parentType = unboundType->getParent ();
907
- if (typealias && (!parentType || !parentType->isAnyExistentialType ())) {
904
+ if (typealias && (!parentTy || !parentTy->isAnyExistentialType ())) {
908
905
auto genericSig = typealias->getGenericSignature ();
909
906
auto subMap = SubstitutionMap::get (genericSig,
910
907
QueryTypeSubstitutionMap{subs},
911
908
LookUpConformanceInModule (module ));
912
- resultType = TypeAliasType::get (typealias, parentType,
913
- subMap, resultType);
909
+ resultType = TypeAliasType::get (typealias, parentTy, subMap, resultType);
914
910
}
915
911
916
912
return resultType;
@@ -3311,17 +3307,16 @@ Type TypeResolver::resolveDictionaryType(DictionaryTypeRepr *repr,
3311
3307
return ErrorType::get (Context);
3312
3308
}
3313
3309
3314
- auto dictDecl = Context.getDictionaryDecl ();
3310
+ auto * const dictDecl = Context.getDictionaryDecl ();
3315
3311
if (!dictDecl) {
3316
3312
Context.Diags .diagnose (repr->getBrackets ().Start ,
3317
3313
diag::sugar_type_not_found, 3 );
3318
3314
return ErrorType::get (Context);
3319
3315
}
3320
3316
3321
- auto unboundTy = dictDecl->getDeclaredType ()->castTo <UnboundGenericType>();
3322
- Type args[] = {keyTy, valueTy};
3323
3317
if (!TypeChecker::applyUnboundGenericArguments (
3324
- unboundTy, dictDecl, repr->getStartLoc (), resolution, args)) {
3318
+ dictDecl, nullptr , repr->getStartLoc (), resolution,
3319
+ {keyTy, valueTy})) {
3325
3320
assert (Context.Diags .hadAnyError ());
3326
3321
return ErrorType::get (Context);
3327
3322
}
0 commit comments