robb / Cartography

A declarative Auto Layout DSL for Swift :iphone::triangular_ruler:
Other
7.34k stars 525 forks source link

Priority Operator Error #241

Closed JohnCoates closed 8 years ago

JohnCoates commented 8 years ago

The priority example in the Readme fails to compile on Swift 3.0

var constraint: NSLayoutConstraint!
constrain(view) { (view: LayoutProxy) in
    constraint = view.width == 200 ~ 100
}            
expect(constraint.priority).to(equal(100))

Errors:

Cartography/CartographyTests/PrioritySpec.swift:22:28: error: adjacent operators are in unordered precedence groups 'AssignmentPrecedence' and 'CarthographyPriorityPrecedence'
                constraint = view.width == 200 ~ 100
                           ^                   ~
Cartography/CartographyTests/PrioritySpec.swift:22:48: error: binary operator '~' cannot be applied to operands of type '()' and 'Int'
                constraint = view.width == 200 ~ 100
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~
Cartography/CartographyTests/PrioritySpec.swift:22:48: note: overloads for '~' exist with these partially matching parameter lists: (NSLayoutConstraint, LayoutPriority), ([NSLayoutConstraint], LayoutPriority)
                constraint = view.width == 200 ~ 100
JohnCoates commented 8 years ago

adding higherThan: AssignmentPrecedence to precedencegroup CarthographyPriorityPrecedence fixes the first error.

Not sure what the best fix for the second & third errors are, but wrapping the priority in LayoutPriority() makes it compile at least. constraint = view.width == 200 ~ LayoutPriority(100)

orta commented 8 years ago

Yeah, the implicit LayoutPriority was something we couldn't figure out when porting to Swift 3 - I'd love for you to dig in here and see if you can figure that one out?

JohnCoates commented 8 years ago

Okay, sure I'll have a go at it

JohnCoates commented 8 years ago

I believe this is a bug with the compiler. I've filed a Swift bug report and a radar about this issue. The more radars that get filed, the more traction the bug gets, so I recommend filing one also.

orta commented 8 years ago

Perfect! Shipped as 1.0.1 - thanks!