Skip to content

Sema: Redeclaration checking should not mark implicit decls as invalid #33548

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
merged 1 commit into from
Aug 19, 2020
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
56 changes: 30 additions & 26 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,44 +754,48 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
declToDiagnose->diagnose(diag::invalid_redecl_implicit,
current->getDescriptiveKind(),
isProtocolRequirement, other->getName());
}

// Emit a specialized note if the one of the declarations is
// the backing storage property ('_foo') or projected value
// property ('$foo') for a wrapped property. The backing or
// projected var has the same source location as the wrapped
// property we diagnosed above, so we don't need to extract
// the original property.
const VarDecl *varToDiagnose = nullptr;
auto kind = PropertyWrapperSynthesizedPropertyKind::Backing;
if (auto currentVD = dyn_cast<VarDecl>(current)) {
if (auto currentKind =
currentVD->getPropertyWrapperSynthesizedPropertyKind()) {
varToDiagnose = currentVD;
kind = *currentKind;
// Emit a specialized note if the one of the declarations is
// the backing storage property ('_foo') or projected value
// property ('$foo') for a wrapped property. The backing or
// projected var has the same source location as the wrapped
// property we diagnosed above, so we don't need to extract
// the original property.
const VarDecl *varToDiagnose = nullptr;
auto kind = PropertyWrapperSynthesizedPropertyKind::Backing;
if (auto currentVD = dyn_cast<VarDecl>(current)) {
if (auto currentKind =
currentVD->getPropertyWrapperSynthesizedPropertyKind()) {
varToDiagnose = currentVD;
kind = *currentKind;
}
}
}
if (auto otherVD = dyn_cast<VarDecl>(other)) {
if (auto otherKind =
otherVD->getPropertyWrapperSynthesizedPropertyKind()) {
varToDiagnose = otherVD;
kind = *otherKind;
if (auto otherVD = dyn_cast<VarDecl>(other)) {
if (auto otherKind =
otherVD->getPropertyWrapperSynthesizedPropertyKind()) {
varToDiagnose = otherVD;
kind = *otherKind;
}
}

if (varToDiagnose) {
assert(declToDiagnose);
varToDiagnose->diagnose(
diag::invalid_redecl_implicit_wrapper, varToDiagnose->getName(),
kind == PropertyWrapperSynthesizedPropertyKind::Backing);
}
}

if (varToDiagnose) {
varToDiagnose->diagnose(
diag::invalid_redecl_implicit_wrapper, varToDiagnose->getName(),
kind == PropertyWrapperSynthesizedPropertyKind::Backing);
current->setInvalid();
}
} else {
ctx.Diags.diagnoseWithNotes(
current->diagnose(diag::invalid_redecl,
current->getName()), [&]() {
other->diagnose(diag::invalid_redecl_prev, other->getName());
});

current->setInvalid();
}
current->setInvalid();
}

// Make sure we don't do this checking again for the same decl. We also
Expand Down
29 changes: 29 additions & 0 deletions validation-test/compiler_crashers_2_fixed/rdar67259506.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %target-swift-frontend -emit-ir %s

public func foo<T : P & Q>(_: T, _: S<T>.A) {}

public protocol P {
associatedtype A

func foo() -> A
}

public protocol Q {
associatedtype A

func bar() -> A
}

public struct S<T> {}

extension S : P where T : P {
public func foo() -> Int {
return 0
}
}

extension S : Q where T : Q {
public func bar() -> Int {
return 0
}
}