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-8696] Types nested in functions and their operator functions. #51209

Closed
AnthonyLatsis opened this issue Sep 5, 2018 · 3 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances duplicate Resolution: Duplicates another issue nested types Feature: nested types operators Feature: operators swift 4.2 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Sep 5, 2018

Previous ID SR-8696
Radar rdar://problem/44479781
Original Reporter @AnthonyLatsis
Type Bug
Status Resolved
Resolution Duplicate
Environment

Version 10.0 beta 6 (10L232m)

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

md5: 2c36821d55436bc84a73cddd636ab9f0

duplicates:

  • SR-3092 Function-level nested types cannot conform to Equatable

is duplicated by:

  • SR-8817 Type nested in function unable to conform to protocols with operator requirements
  • SR-8872 Operators for local types not working

relates to:

  • SR-8672 Hashable struct in function
  • SR-3092 Function-level nested types cannot conform to Equatable

Issue Description:

An operator function requirement cannot be satisfied if the type is nested in a function. The issue applies only to operator functions, renaming < to foo makes the error disappear.

protocol P { 
  static func < (lhs: Self, rhs: Self) -> Bool 
}

func f() {
  struct B: P { // type 'B' does not conform to protocol 'P'
    static func < (lhs: B, rhs: B) -> Bool { return true }
  }
}
@jepers
Copy link

jepers commented Sep 5, 2018

Here is a simpler example (without protocols) of what I think might be the root issue:
For example, this works:

struct S {
    var v: Int
    static func +(lhs: S, rhs: S) -> S { return S(v: lhs.v + rhs.v) }
}
func foo() {
    print(S(v: 123) + S(v: 456)) // 579
}
foo()

But this doesn't:

func foo() {
    struct S {
        var v: Int
        static func +(lhs: S, rhs: S) -> S { return S(v: lhs.v + rhs.v) }
    }
    print(S(v: 123) + S(v: 456)) // ERROR: Binary operator '+' cannot be applied to two 'S' operands
}
foo()

I happened to add this example to SR-8672 before I saw this bug (linked SR-8672 as related).

@jepers
Copy link

jepers commented Sep 5, 2018

@belkadan
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2022
@AnthonyLatsis AnthonyLatsis added duplicate Resolution: Duplicates another issue type checker Area → compiler: Semantic analysis conformances Feature → protocol: protocol conformances operators Feature: operators nested types Feature: nested types unexpected error Bug: Unexpected error swift 4.2 labels Feb 22, 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. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances duplicate Resolution: Duplicates another issue nested types Feature: nested types operators Feature: operators swift 4.2 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error
Projects
None yet
Development

No branches or pull requests

3 participants