Skip to content

Commit 5dbd653

Browse files
authored
[Sema] Fix derived property setter logic. (#21995)
Derived property setters should inherit their parent's generic environment. This logic already existed in `declareDerivedPropertyGetter` but wasn't copied to `declareDerivedPropertySetter` for some reason. Add test using a derived `Differentiable.allDifferentiableVariables` setter in a generic nominal type.
1 parent c69d291 commit 5dbd653

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/Sema/DerivedConformances.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ DerivedConformance::declareDerivedPropertySetter(TypeChecker &tc,
483483
if (isFinal && parentDC->getSelfClassDecl() &&
484484
!setterDecl->isFinal())
485485
setterDecl->getAttrs().add(new (C) FinalAttr(/*Implicit*/ true));
486+
487+
// Compute the interface type of the setter.
488+
if (auto env = parentDC->getGenericEnvironmentOfContext())
489+
setterDecl->setGenericEnvironment(env);
486490
setterDecl->computeType();
487491
setterDecl->copyFormalAccessFrom(property);
488492
setterDecl->setValidationToChecked();

test/Sema/struct_differentiable.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ func testKeyPathIterable(x: TestKeyPathIterable) {
163163
_ = x.allDifferentiableVariables.allKeyPaths
164164
}
165165

166+
// Test type with generic environment.
167+
struct HasGenericEnvironment<Scalar : FloatingPoint & Differentiable> : Differentiable {
168+
var x: Float
169+
}
170+
166171
/*
167172
// Test type with generic members that conform to `Differentiable`.
168173
// Since it's not the case that

0 commit comments

Comments
 (0)