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

Unexpected behavior of variadic parameters

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

      Xcode 10.2.1

      Description

      https://forums.swift.org/t/unexpected-behavior-of-variadic-parameters/23892

      class Test {
          func test() {
              print("test")
          }
          
          func test(_ values: Int...) {
              print(values)
          }
      }
      
      let t = Test()
      t.test() // prints test
      

      However if func test() is implemented in extension of Protocol, it behaves different.

       

      protocol P {
          func test()
      }
      
      extension P {
          func test() {
              print("test")
          }
      }
      
      class Test: P {
      //    func test() {
      //        print("test")
      //    }
          
          func test(_ values: Int...) {
              print(values)
          }
      }
      
      let t = Test()
      t.test() // prints []
      

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              linqingmo LinQingmo
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: