Comments (3)
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.
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.
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)
- Parameter packs produce crashes on synthesized memberwise init HOT 1
- Mutating main actor-isolated property from non-main actor-isolated context does not produce compiler error
- Macro shadows methods and properties defined in protocol extension a type inherits
- Macro unable to suppress redundant conformance if type inherits it from another protocol
- Compiler crash when passing variadic generic parameter to a function HOT 1
- Codable Class Causes Warning When Using @Observable Macro HOT 1
- Swift Macros: Adding an enum case with an associated value produces incorrect results
- Variant of function types for functions marked with the rethrows keyword
- C++ interop: non-copyable: fix an issue with windows use of HasDest for unique_ptr test
- Bad diagnostic for pack type count mismatch in function call
- Macro: compiler should throw error when extension macro generates extensions for other types
- Compiler bug with consume keyword
- [TabularData] DataFrame literal constructor incorrectly detects types of empty columns
- lib/SymbolGraphGen is discarding PATs from declarations HOT 2
- C++ interop: non-copyable: fix an issue with move-only-cxx-value-type-generics.swift once non-copyable generics are supported: isLoadableOrOpaque(operand->getType())) HOT 1
- Deserialization failure (XRefError) compiler crashes where certain std::vector related instantiated types are not found with C++ interop HOT 1
- Unicode ZWNJ Recognition Issue HOT 1
- Range.contains(Range) currently checks all values instead of a bounds check, taking a very long time for large ranges. HOT 2
- Obj-C++ interop fails to import with ARC errors, seems to ignore `-fno-objc-arc` flag HOT 1
- InitializerDeclSyntax faiiled to catch syntax error and caused compiler hang HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift.