Uploaded image for project: 'Swift'
  1. Swift
  2. SR-4541

Class-Only protocol inheriting from normal protocol require to be var to allow assign to their properties.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Invalid
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

      OS X 10.11.6 (15G1217)
      Xcode Version 8.2.1 (8C1002)

      Description

      In this scenario:

      protocol CoolProtocol {
          var coolness: Int { get set }
      }
      
      protocol CoolClassProtocol: class, CoolProtocol {
         // if you re-declare coolness here all works as expected
         // var coolness: Int { get set }
      }
      
      class Cool {
          var coolness = 1
      }
      
      func incrementCool(_ cool: CoolClassProtocol) {
         // here you get compiler error saying cool should be var.
         // if you do it as in: 
         // var cool = cool
         // you'll get a warning telling you that cool is never mutated and should be made a let constant.
          cool.coolness += 1
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              erne Ernesto Giannotta
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: