Skip to content

[5.1 08-28] Sema: Compare canonical bound signatures when comparing o… #26935

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
3 changes: 2 additions & 1 deletion lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,8 @@ static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
if (matchMode.contains(TypeMatchFlags::AllowCompatibleOpaqueTypeArchetypes))
if (auto opaque1 = t1->getAs<OpaqueTypeArchetypeType>())
if (auto opaque2 = t2->getAs<OpaqueTypeArchetypeType>())
return opaque1->getBoundSignature() == opaque2->getBoundSignature() &&
return opaque1->getBoundSignature()->getCanonicalSignature() ==
opaque2->getBoundSignature()->getCanonicalSignature() &&
opaque1->getInterfaceType()->getCanonicalType()->matches(
opaque2->getInterfaceType()->getCanonicalType(), matchMode);

Expand Down
15 changes: 14 additions & 1 deletion test/type/opaque.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -disable-availability-checking -typecheck -verify -enable-opaque-result-types %s
// RUN: %target-swift-frontend -disable-availability-checking -typecheck -verify -enable-opaque-result-types %s -swift-version 5

protocol P {
func paul()
Expand Down Expand Up @@ -473,3 +473,16 @@ func invoke_52528543<T: P_52528543, U: P_52528543>(x: T, y: U) {
var xab = f_52528543(x: x2)
xab = f_52528543(x: y2) // expected-error{{cannot assign}}
}

protocol Proto {}

struct I : Proto {}

dynamic func foo<S>(_ s: S) -> some Proto {
return I()
}

@_dynamicReplacement(for: foo)
func foo_repl<S>(_ s: S) -> some Proto {
return I()
}