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-6706] Swift should complain about weak references to classes that don't support them #49255

rjmccall opened this issue Jan 5, 2018 · 1 comment
compiler The Swift compiler in itself good first issue Good for newcomers improvement


Copy link

rjmccall commented Jan 5, 2018

Previous ID SR-6706
Radar rdar://problem/17171033
Original Reporter @rjmccall
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, StarterBug
Assignee @ChristopherRogers
Priority Medium

md5: c8c885eba41db6083c685ccae0478cf5

Issue Description:

Objective-C has some classes that don't support the ObjC weak-reference machinery, and therefore Clang warns about making a __weak reference to such a class. Swift's weak and unowned references depend on that same machinery for ObjC classes, so we should have a similar diagnostic; I think ours should just be a hard error, though.

Note that attributes like IBOutlet imply making a weak reference, and we should make sure the diagnostic catches them as well. Or maybe we should just make the outlet implicitly unowned(unsafe)?

The code from the Clang compiler that performs this check is as follows; this bug is mostly a matter of doing a similar check when checking a weak/unowned reference in Swift.

  if (lifetime == Qualifiers::OCL_Weak) {
    if (const ObjCObjectPointerType *ObjT =
          type->getAs<ObjCObjectPointerType>()) {
      if (ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl()) {
        if (Class->isArcWeakrefUnavailable()) {
          S.Diag(AttrLoc, diag::err_arc_unsupported_weak_class);
Copy link

Here's my PR for this. #17792

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
compiler The Swift compiler in itself good first issue Good for newcomers improvement
None yet

No branches or pull requests

2 participants