Skip to content

Sema: Fix crash on static -vs- non-static witness mismatch with deserialized witness [5.3] #34013

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
7 changes: 5 additions & 2 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,13 +2311,16 @@ diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
if (auto FD = dyn_cast<FuncDecl>(witness)) {
loc = FD->getStaticLoc();
} else if (auto VD = dyn_cast<VarDecl>(witness)) {
loc = VD->getParentPatternBinding()->getStaticLoc();
if (auto PBD = VD->getParentPatternBinding()) {
loc = PBD->getStaticLoc();
}
} else if (auto SD = dyn_cast<SubscriptDecl>(witness)) {
loc = SD->getStaticLoc();
} else {
llvm_unreachable("Unexpected witness");
}
diag.fixItRemove(loc);
if (loc.isValid())
diag.fixItRemove(loc);
} else {
diag.fixItInsert(witness->getAttributeInsertionLoc(true), "static ");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public struct TimeZone {
public static var current: TimeZone { return TimeZone() }
}
16 changes: 16 additions & 0 deletions test/decl/protocol/deserialized_witness_mismatch.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/Inputs/deserialized_witness_mismatch_other.swift -emit-module-path %t/deserialized_witness_mismatch_other.swiftmodule
// RUN: %target-swift-frontend -I %t/ %s -typecheck -verify

// Deserialized computed properties don't have a PatternBindingDecl, so
// make sure we don't expect to find one.

import deserialized_witness_mismatch_other

protocol HasCurrent {
var current: Self { get }
// expected-note@-1 {{protocol requires property 'current' with type 'TimeZone'; do you want to add a stub?}}
}

extension TimeZone : HasCurrent {}
// expected-error@-1 {{type 'TimeZone' does not conform to protocol 'HasCurrent'}}