Skip to content

Commit ee52e73

Browse files
committed
[SE-0258] Don't ask for the nominal type decl of an unresolved property wrapper
Generic type aliases break this query; don't use it. Fixes rdar://problem/51989272
1 parent 749a972 commit ee52e73

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ getEnclosingSelfPropertyWrapperAccess(VarDecl *property, bool forProjected) {
640640
return None;
641641

642642
// The pattern currently only works with the outermost property wrapper.
643-
Type outermostWrapperType = property->getAttachedPropertyWrapperType(0);
643+
Type outermostWrapperType = property->getPropertyWrapperBackingPropertyType();
644644
if (!outermostWrapperType)
645645
return None;
646646
NominalTypeDecl *wrapperTypeDecl = outermostWrapperType->getAnyNominal();

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,7 @@ AttachedPropertyWrapperTypeRequest::evaluate(Evaluator &evaluator,
513513
if (tc.validateType(customAttr->getTypeLoc(), resolution, options))
514514
return ErrorType::get(ctx);
515515

516-
Type customAttrType = customAttr->getTypeLoc().getType();
517-
if (!customAttrType->getAnyNominal()) {
518-
assert(ctx.Diags.hadAnyError());
519-
return ErrorType::get(ctx);
520-
}
521-
522-
return customAttrType;
516+
return customAttr->getTypeLoc().getType();
523517
}
524518

525519
llvm::Expected<Type>
@@ -531,7 +525,7 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
531525
return rawTypeResult;
532526

533527
Type rawType = *rawTypeResult;
534-
if (!rawType)
528+
if (!rawType || rawType->hasError())
535529
return Type();
536530

537531
if (!rawType->hasUnboundGenericType())
@@ -578,7 +572,7 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
578572
if (!rawWrapperType)
579573
return Type();
580574

581-
// Open the
575+
// Open the type.
582576
Type openedWrapperType =
583577
cs.openUnboundGenericType(rawWrapperType, emptyLocator);
584578
if (!outermostOpenedWrapperType)

test/decl/var/property_wrappers.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,17 @@ struct SomeA<T> {
886886
}
887887
}
888888

889+
// rdar://problem/51989272 - crash when the property wrapper is a generic type
890+
// alias
891+
typealias Alias<T> = WrapperWithInitialValue<T>
892+
893+
struct TestAlias {
894+
@Alias var foo = 17
895+
}
896+
897+
898+
899+
//
889900
// ---------------------------------------------------------------------------
890901
// Property wrapper composition
891902
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)