Skip to content

[Tests] NFC: Add a couple of tests for parametrized opaque result types #72493

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
Mar 25, 2024
Merged
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
21 changes: 21 additions & 0 deletions test/type/opaque.swift
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,24 @@ func f62787_1(x: Bool) -> Optional<some Collection<Int>> {
}
return nil // expected-error{{underlying type for opaque result type 'Optional<some Collection<Int>>' could not be inferred from return expression}}
}

// rdar://124482122 - Make sure that constraints are respected by opaque types
protocol P3<A> {
associatedtype A: P1
}

do {
struct G<A: P1>: P3 {}

struct S: P1 {}

func test1() -> some P3<Int> { // expected-note {{opaque return type declared here}}
return G<S>()
// expected-error@-1 {{type of local function 'test1()' requires that 'S' conform to 'Int'}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to fix the diagnostic to take requirement kind into account too? :) It seems it was hardcoded to RequirementKind::Conformance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll look into that!

}

func test2() -> some P3<G<S>> { // expected-note {{opaque return type declared here}}
return G<S>()
// expected-error@-1 {{return type of local function 'test2()' requires that 'S' conform to 'G<S>'}}
}
}