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

Override checking does not properly enforce requirements

    XMLWordPrintable

    Details

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

      Swift Ver. 3.0.2

      Description

      protocol Parent {}
      
      protocol A: Parent {}
      protocol B: Parent {}
      
      struct Foo: A {}
      
      class ClassA {
          func foo<T: A>(param: T) {
              print("A")
          }
      }
      
      class ClassB: ClassA {
          override func foo<T: A>(param: T) {
              print("A")
          }
      
          override func foo<T: B>(param: T) {
              print("B")
          }
      
      }
      
      let foo = Foo()
      let classB = ClassB()
      classB.foo(param: foo)
      

      Expected result: "A" will be printed
      Actual result: "B" is printed

      If we remove foo<T: A> overload compiler will complain argument type 'Foo' does not conform to expected type 'B'.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              slavapestov Slava Pestov
              Reporter:
              Pr0Ger Sergey Petrov
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: