Skip to content

Rdar 27397701 synthesized get set typechecking #5588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4593,7 +4593,9 @@ DynamicSelfType *FuncDecl::getDynamicSelfInterface() const {

SourceRange FuncDecl::getSourceRange() const {
SourceLoc StartLoc = getStartLoc();
if (StartLoc.isInvalid()) return SourceRange();
if (StartLoc.isInvalid() ||
getBodyKind() == BodyKind::Synthesize)
return SourceRange();

if (getBodyKind() == BodyKind::Unparsed ||
getBodyKind() == BodyKind::Skipped)
Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,17 +763,15 @@ void swift::addTrivialAccessorsToStorage(AbstractStorageDecl *storage,

// Synthesize and type-check the body of the getter.
synthesizeTrivialGetter(getter, storage, TC);
TC.typeCheckDecl(getter, true);
TC.typeCheckDecl(getter, false);
TC.validateDecl(getter);

if (setter) {
if (isDynamic)
setter->getAttrs().add(new (TC.Context) DynamicAttr(IsImplicit));

// Synthesize and type-check the body of the setter.
synthesizeTrivialSetter(setter, storage, setterValueParam, TC);
TC.typeCheckDecl(setter, true);
TC.typeCheckDecl(setter, false);
TC.validateDecl(setter);
}

auto *DC = storage->getDeclContext();
Expand Down
15 changes: 15 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3615,6 +3615,21 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
}
}

// Typecheck any accessors that were previously synthesized
// (that were previously only validated at point of synthesis)
if (auto getter = VD->getGetter()) {
if (getter->hasBody()) {
TC.typeCheckDecl(getter, true);
TC.typeCheckDecl(getter, false);
}
}
if (auto setter = VD->getSetter()) {
if (setter->hasBody()) {
TC.typeCheckDecl(setter, true);
TC.typeCheckDecl(setter, false);
}
}

TC.checkDeclAttributes(VD);
}

Expand Down
1 change: 1 addition & 0 deletions lib/Sema/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ static void typeCheckFunctionsAndExternalDecls(TypeChecker &TC) {

} while (currentFunctionIdx < TC.definedFunctions.size() ||
currentExternalDef < TC.Context.ExternalDefinitions.size() ||
!TC.ValidatedTypes.empty() ||
!TC.UsedConformances.empty());

// FIXME: Horrible hack. Store this somewhere more appropriate.
Expand Down
10 changes: 10 additions & 0 deletions validation-test/compiler_scale/scale_neighbouring_getset.gyb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %scale-test --sum-multi --parse --begin 5 --end 16 --step 5 --select typeCheckAbstractFunctionBody %s
// REQUIRES: tools-release

struct Struct${N} {
% if int(N) > 1:
var Field : Struct${int(N)-1}?
% else:
var Field : Int?
% end
}