Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-6265] Remove "redundant layout constraint" warning #48815

Closed
NachoSoto opened this issue Nov 1, 2017 · 11 comments
Closed

[SR-6265] Remove "redundant layout constraint" warning #48815

NachoSoto opened this issue Nov 1, 2017 · 11 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation regression swift 4.0

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-6265
Radar None
Original Reporter @NachoSoto
Type Bug
Environment

Swift version 4.0.2 (swiftlang-900.0.69.1 clang-900.0.38)

Additional Detail from JIRA
Votes 11
Component/s Compiler
Labels Bug, 4.0Regression, DiagnosticsQoI
Assignee None
Priority Medium

md5: 6696c6112b38ed2330b27fc56449fc4b

relates to:

  • SR-5753 Remove "redundant same-type constraints" warnings
  • SR-7048 Layout constraint warning or compilation error

Issue Description:

This is basically the same as SR-5753.
This was my code (see Twitter conversation too):

protocol A: class {}
protocol B: class, A {}

Starting from Swift 4.0.2 (Xcode 9.1), I started getting this warning:

error: redundant layout constraint 'Self' : 'AnyObject'

Which, for starters, is not user friendly at all. The `'Self' : 'AnyObject'` part is totally a Swift implementation detail. But most importantly, I don't think this warning carries its weight. In my case, I don't want to rely on A enforcing reference semantics. What if A drops that constraint? I want B to always have them.

So like I said in SR-5753, without a way to turn these warnings off either globally or for a particular declaration, I think they're more annoying than anything.

@belkadan
Copy link
Contributor

belkadan commented Nov 1, 2017

cc @DougGregor

@swift-ci
Copy link
Collaborator

Comment by Matthew Rips (JIRA)

On the off chance this regression is intended, I offer the following example in which the "redundancy" seems unavoidable.

protocol A: class {}
protocol B: class {}
protocol C: A, B {}

If this warning is to continue, then let's please revise the content of the message. Use of the term "layout constraint" is very confusing.

Thank you!

@NachoSoto
Copy link
Contributor Author

👍

@swift-ci
Copy link
Collaborator

Comment by Rob Nash (JIRA)

Also note

public protocol CardableScene: class where Self: UIViewController {
  associatedtype Model: Equatable
  var showsNavigationBar: Bool { get }
  init(model: Model)
  var model: Model { get }
}

public extension CardableScene {
  
  var showsNavigationBar: Bool {
    return navigationItem.title != nil
  }
}

At runtime

(lldb) po scene.showsNavigationBar
2017-12-20 07:30:23.558169+0000 DanceClass[1194:29854] +[DanceClass.DanceClassViewController navigationItem]: unrecognized selector sent to class 0x109344cd0
error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value couldn't be evaluated

@belkadan
Copy link
Contributor

That has nothing to do with this issue; please file a separate bug.

@ZevEisenberg
Copy link
Contributor

Does "layout constraint" mean something in the context of Swift? Or was this written by someone who has muscle memory from using Auto Layout?

@belkadan
Copy link
Contributor

It does; it refers to how the value is laid out in memory. I'm not sure we really want to be using this term for : AnyObject, though. @DougGregor?

@DougGregor
Copy link
Member

"Layout" is a poor term to use here, because the layout aspects are compiler-centric, not user-focused.

@swift-ci
Copy link
Collaborator

Comment by Ky (JIRA)

I'm getting this without any redundancy at all:

// A protocol where each instance is guaranteed to be a NSViewController
protocol Foo where Self : NSViewController {}

@swift-ci
Copy link
Collaborator

Comment by Joseph Gentry (JIRA)

If I remove the class descriptor to remove redundancy I will get a crash at runtime when calling the protocol method.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@slavapestov
Copy link
Member

Redundant requirement warnings are now disabled by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation regression swift 4.0
Projects
None yet
Development

No branches or pull requests

7 participants