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-14277] Build error referencing RawValue.Stride for C imported enum #56636

Closed
swift-ci opened this issue Feb 26, 2021 · 3 comments · Fixed by #65514
Closed

[SR-14277] Build error referencing RawValue.Stride for C imported enum #56636

swift-ci opened this issue Feb 26, 2021 · 3 comments · Fixed by #65514
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c interop Feature: Interoperability with C compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances enum Feature → type declarations: Swift enumeration declarations extension Feature → declarations: `extension` declarations protocol Feature → type declarations: Protocol declarations swift 5.3 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14277
Radar rdar://problem/74794074
Original Reporter lhunath (JIRA User)
Type Bug
Environment

Swift 5.3

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

md5: a81833ca13b773dcb09510610bc2d844

Issue Description:

The following enum:

typedef NS_ENUM( uint32_t, Letter ) {
    a,
    b,
};

Causes the following code to fail in the compiler:

extension Letter: Strideable {
    public func distance(to other: Self) -> RawValue.Stride {
        self.rawValue.distance( to: other.rawValue )
    }

    public func advanced(by n: RawValue.Stride) -> Self {
        Self( rawValue: self.rawValue.advanced( by: n ) )!
    }
}

With the following error:

<unknown>:0: error: circular reference

However, if we replace the imported type with a native equivalent:

enum Letter : UInt32 {
    case a, b
}

The error goes away.

It is unclear what is supposedly circular about the code in question.

The error can also be avoided by changing this:

    public func distance(to other: Self) -> RawValue.Stride {

into this:

    public func distance(to other: Self) -> Int {

Suggesting the issue is with the resolution of Self.Stride

@swift-ci
Copy link
Collaborator Author

Comment by Maarten Billemont (JIRA)

If there is any documentation on exactly how Swift imports native C objects such as enums, in detail (including their synthesized Swift representation and protocols), that would be very helpful; I haven't been able to find any such documentation.

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
slavapestov added a commit to slavapestov/swift that referenced this issue Apr 28, 2023
@slavapestov
Copy link
Member

No longer reproduces, I'm adding a regression test.

slavapestov added a commit to slavapestov/swift that referenced this issue Apr 28, 2023
slavapestov added a commit that referenced this issue May 1, 2023
@AnthonyLatsis AnthonyLatsis added c interop Feature: Interoperability with C enum Feature → type declarations: Swift enumeration declarations unexpected error Bug: Unexpected error type checker Area → compiler: Semantic analysis swift 5.3 conformances Feature → protocol: protocol conformances extension Feature → declarations: `extension` declarations protocol Feature → type declarations: Protocol declarations labels May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c interop Feature: Interoperability with C compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances enum Feature → type declarations: Swift enumeration declarations extension Feature → declarations: `extension` declarations protocol Feature → type declarations: Protocol declarations swift 5.3 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error
Projects
None yet
4 participants