Giter VIP home page Giter VIP logo

Comments (3)

swift-ci avatar swift-ci commented on May 21, 2024

Comment by Nikita Leonov (JIRA)

I had the same issue reported as radar, and duplicated it here as well SR-41. Sorry for duplication, as I didn't expect this issue to be so popular and already reported by someone else. Apparently there was one already reported.

from swift.

swift-ci avatar swift-ci commented on May 21, 2024

Comment by Steven Downum (JIRA)

This is probably not unexpected considering the nature of the issue, but I was able to yield a very similar result under Ubuntu 14.04:

  6> func variadic(numbers: Int...) {}
  7> [1].forEach(variadic)
lldb: /home/buildslave/jenkins/workspace/oss-swift-linux-packages-ubuntu_14_04-one-off-build/swift/lib/SILGen/SILGenExpr.cpp:1799: void emitTupleShuffleExprInto((anonymous namespace)::RValueEmitter &, swift::TupleShuffleExpr *, swift::Lowering::Initialization *): Assertion `innerMapping >= 0 && "non-argument tuple shuffle with default arguments or variadics?"' failed.
Aborted

I can add to SR-41, if desired.

from swift.

CodaFi avatar CodaFi commented on May 21, 2024

This one is resolved in master by the type error.

Variadics are a distinct type from "ground types". If you want to pass them around, you have to explicitly annotate the function as accepting that kind of type. Swift's type system does not support arity-generic overloads like you suspect it should here (though this may be something you could go through the evolution process to ask for if you think it is a useful feature). If you need to invoke these variadic functions, you must explicitly apply the necessary number of arguments. For example:

func giveMeVoid(callback: (Void)->Void) {
  
}

func giveMeInt(callback: (Int)->Void) {
  
}

func any(values:Any?...) {
  
}

any()
any(values: 5)

giveMeVoid { any() }
giveMeInt { any(values: $0) } 

If you need to pass these functions, then you can annotate the types of each function as accepting a variadic number of arguments and we'll figure out the rest for you (but you must maintain invariance [as though they were an [Blah] instead of Blah...])

func giveMeInt(callback: (Int...)->Void) {
  
}

func any(values:Int...) {
  
}

giveMeInt(any) 

from swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.