Skip to content
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

[SR-14731] Self<T> is allowed in generic type, but it doesn't work as expected. #57081

Closed
swift-ci opened this issue Jun 6, 2021 · 4 comments

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 6, 2021

Previous ID SR-14731
Radar rdar://problem/79051797
Original Reporter ensan (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)
Target: x86_64-apple-darwin20.5.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: a6580430cf4875efea2b6580bfa43a4f

Issue Description:

I couldn't find previous report about this behavior. Perhaps this is a known-issue, but just in case.

struct Wrapper<A> {
    // actually WrapperInt is Wrapper<A>
    typealias WrapperInt = Self<Int>
}

I read https://bugs.swift.org/browse/SR-7666, but about this, compiler should cause at least warning, because it must not work as expected. If `Self` stands for `Wrapper`, it should work as expected. If `Self` stands for `Wrapper<A>` then it should be error, because `Wrapper<A><Int>` doesn't make sense.

@typesanitizer
Copy link

typesanitizer commented Jun 9, 2021

You're right, this should be an error instead of being silently ignored.

@swift-ci create

@CodaFi
Copy link
Member

CodaFi commented Jun 10, 2021

Huh, seems like we're not substituting this thing correctly

struct Wrapper<A> {
    // actually WrapperInt is Wrapper<A>
    typealias WrapperInt = Self<Int>

    func eat(_ x: WrapperInt) {
      x.foo() // error!
    }
}

extension Wrapper where A == Int {
  func foo() {}
}

@slavapestov
Copy link
Member

slavapestov commented Jun 11, 2021

Yeah, I agree that this should be an error. The original proposal did not say anything about substituting in alternate generic arguments with `Self`.

@slavapestov
Copy link
Member

slavapestov commented Jun 16, 2021

#37891

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants