Some syntax errors in Swift's standard library, anyone knows why?

22 views
Skip to first unread message

l̲̅e̲̅x̲̅ c̲̅h̲̅o̲̅u̲̅

unread,
Apr 27, 2015, 10:33:14 AM4/27/15
to swift-l...@googlegroups.com
I found several undocumented syntax in swift's standard library, or maybe we should call it syntax error, because these syntaxes even not supported by Xcode and Swift compiler:

func join<S : SequenceType where [T] == [T]>(elements: S) -> [T]

This is defined by type Swift.Array, according to Language References - Where Clauses, it must be an identifier after where for same-type-requirement, so it's a syntax-level error, and it's even not right in semantic level, I don't understand why there's a [T] = [T] requirement, anyone knows?

Another undocumented syntax example:

    mutating func removeAll(keepCapacity: Bool = default)


This is easy to understand although it's still not a valid swift syntax.

Jens Alfke

unread,
Apr 27, 2015, 12:53:12 PM4/27/15
to l̲̅e̲̅x̲̅ c̲̅h̲̅o̲̅u̲̅, swift-l...@googlegroups.com

On Apr 27, 2015, at 7:33 AM, l̲̅e̲̅x̲̅ c̲̅h̲̅o̲̅u̲̅ <lex...@gmail.com> wrote:

I found several undocumented syntax in swift's standard library

I assume you’re finding these by Command-clicking in Xcode? That’s not the actual source code (which isn’t public.) It’s something Xcode generates on the fly by decompiling metadata in the compiled code. It’s entirely possible this decompiler has glitches that cause it to emit incorrect or nonsensical source code in some cases, and I’m guessing that’s what you’ve found. You could file a bug report with Apple.

—Jens

Chris Lattner

unread,
Apr 27, 2015, 12:55:58 PM4/27/15
to Jens Alfke, l̲̅e̲̅x̲̅ c̲̅h̲̅o̲̅u̲̅, swift-l...@googlegroups.com
Yep, that’s exactly the case.  It is a known bug, thanks!

-Chris

l̲̅e̲̅x̲̅ c̲̅h̲̅o̲̅u̲̅

unread,
Apr 27, 2015, 6:35:50 PM4/27/15
to swift-l...@googlegroups.com
@Jens Alfke @Chris Lattner
Thanks all!
Reply all
Reply to author
Forward
0 new messages