-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Missing fix-it when opaque property type is inferred #69241
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
Comments
This compiles on the main branch. @hborla Is this a regression? |
Gah, I thought I had tested this on my latest toolchain, but I had not. Verified working on this version of Swift:
|
@natecook1000 I'm seeing a similar issue here… I'm trying to resolve a generic constraint using that opaque type. For some reason I seem to be breaking when I'm creating those variables inside the scope of a protocol Proto {}
struct Concrete: Proto {}
func getProto() -> some Proto { Concrete() }
let value = getProto()
struct Wrapper<P: Proto> {
let value: P
init(_ wrappedValue: P) {
self.value = wrappedValue
}
var wrappedValue: P {
self.value
}
}
let w1 = Wrapper(getProto())
let w2 = Wrapper(value)
struct S1 {
let w1 = Wrapper(getProto())
// Property definition has inferred type 'Wrapper<some Proto>', involving the 'some' return type of another declaration
let w2 = Wrapper(value)
// Property definition has inferred type 'Wrapper<some Proto>', involving the 'some' return type of another declaration
} I tested this and saw the same error on the three latest toolchains:
|
@natecook1000 @AnthonyLatsis I'm still unable to build that last example on 5.10 and 6.0. Are there any other open tasks for similar issues I can follow along and watch for? Thanks! |
Reopening with this test case: func foo() -> some Equatable { 0 }
struct S1 {
let w0 = foo()
} Context: #73661 (comment) |
Mind if I take a shot at this? 👀 |
When a pattern binding at top level attempts to pick up another declaration's opaque result type as its type by type inference, provide a fixit to explicitly declare the type. This is done to prevent opaque result types from propagating nontrivially into other declarations' types, see 6db0540
Description
When the type of a variable or property is inferred as an opaque type, the compiler emits an error to that effect:
Steps to reproduce
When compiling this code, the last line has the above error attached.:
Expected behavior
Since the fix is straightforward and included in the error message, the compiler should offer a fixit that would rectify the problem:
Environment
The text was updated successfully, but these errors were encountered: