Skip to content

Commit

Permalink
Add init(styles: StyleParameter...) to Color.Wrap.
Browse files Browse the repository at this point in the history
As of `swift-600��.0.57.3`, the following statement errors:
«Extra argument 'style' in call»
`Color.Wrap(style: .Bold)`

Removing the supposedly "extra" argument 'style' errors:
«'().Type' does not have a member named 'Bold'»
`Color.Wrap(.Bold)`

The true problem appears to be the ambiguity between the
two functions of the form `init(foreground:background:style:)`.

`init(styles: StyleParameter...)` for `Color.Wrap` creates a non-ambiguous initializer.
  • Loading branch information
jdhealy committed Feb 2, 2015
1 parent fdd0bd9 commit 2f5fc69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Source/Color/Wrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public struct Wrap: SelectGraphicRenditionWrapType {
self.init(parameters: parameters)
}

public init(styles: StyleParameter...) {
var parameters: [Parameter] = []

for parameter in styles {
parameters.append(parameter)
}

self.init(parameters: parameters)
}

//------------------------------------------------------------------------------
// MARK: - SelectGraphicRenditionWrap
//------------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions Tests/PrettyColorsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class PrettyColorsTests: XCTestCase {
Color.Wrap(foreground: nil as UInt8?, style: .Bold)
Color.Wrap(foreground: nil as Color.Named.Color?, style: .Bold)
[StyleParameter.Bold] as Color.Wrap
Color.Wrap(styles: .Bold)

// Multiple
Color.Wrap(styles: .Bold, .Blink)
}

func test_problem_TypeInference() {
Expand Down Expand Up @@ -182,6 +186,10 @@ class PrettyColorsTests: XCTestCase {
)
}(red)

XCTAssert(
red + Color.Wrap(styles: .Bold) == Color.Wrap(foreground: .Red, style: .Bold)
)

// Multiple
let _ = { (wrap: Color.Wrap) -> Void in
var formerlyRed = wrap
Expand All @@ -199,6 +207,10 @@ class PrettyColorsTests: XCTestCase {
formerlyRed == Color.Wrap(foreground: .Red, style: .Bold, .Italic)
)
}(red)

XCTAssert(
red + Color.Wrap(styles: .Bold, .Italic) == Color.Wrap(foreground: .Red, style: .Bold, .Italic)
)
}

func testMutableAppend() {
Expand Down

0 comments on commit 2f5fc69

Please sign in to comment.