Skip to content

Commit c2b7d82

Browse files
authored
Merge pull request #59198 from SerenaKit/serena/update-IBInspectable-message
Change message of `invalid_iboutlet` and `invalid_ibinspectable` to reflect accurate usage
2 parents 0f0e721 + 4cf51af commit c2b7d82

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,8 +1408,6 @@ ERROR(transparent_in_protocols_not_supported,none,
14081408
ERROR(transparent_in_classes_not_supported,none,
14091409
"'@_transparent' attribute is not supported on declarations within classes", ())
14101410

1411-
ERROR(invalid_iboutlet,none,
1412-
"only instance properties can be declared @IBOutlet", ())
14131411
ERROR(iboutlet_nonobjc_class,none,
14141412
"@IBOutlet property cannot %select{have|be an array of}0 "
14151413
"non-'@objc' class type %1", (bool, Type))
@@ -1431,8 +1429,8 @@ NOTE(note_make_implicitly_unwrapped_optional,none,
14311429
ERROR(invalid_ibdesignable_extension,none,
14321430
"@IBDesignable can only be applied to classes and extensions "
14331431
"of classes", ())
1434-
ERROR(invalid_ibinspectable,none,
1435-
"only instance properties can be declared @%0", (StringRef))
1432+
ERROR(attr_must_be_used_on_class_instance,none,
1433+
"only class instance properties can be declared @%0", (StringRef))
14361434
ERROR(invalid_ibaction_decl,none,
14371435
"only instance methods can be declared @%0", (StringRef))
14381436
ERROR(invalid_ibaction_result,none,

include/swift/Migrator/FixitFilter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ struct FixitFilter {
5151
return false;
5252
// The following interact badly with the swift migrator by removing @IB*
5353
// attributes when there is some unrelated type issue.
54-
if (Info.ID == diag::invalid_iboutlet.ID ||
55-
Info.ID == diag::iboutlet_nonobjc_class.ID ||
54+
if (Info.ID == diag::iboutlet_nonobjc_class.ID ||
5655
Info.ID == diag::iboutlet_nonobjc_protocol.ID ||
5756
Info.ID == diag::iboutlet_nonobject_type.ID ||
5857
Info.ID == diag::iboutlet_only_mutable.ID ||
5958
Info.ID == diag::invalid_ibdesignable_extension.ID ||
60-
Info.ID == diag::invalid_ibinspectable.ID ||
59+
Info.ID == diag::attr_must_be_used_on_class_instance.ID ||
6160
Info.ID == diag::invalid_ibaction_decl.ID)
6261
return false;
6362

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,16 +632,16 @@ void AttributeChecker::visitIBInspectableAttr(IBInspectableAttr *attr) {
632632
// Only instance properties can be 'IBInspectable'.
633633
auto *VD = cast<VarDecl>(D);
634634
if (!VD->getDeclContext()->getSelfClassDecl() || VD->isStatic())
635-
diagnoseAndRemoveAttr(attr, diag::invalid_ibinspectable,
636-
attr->getAttrName());
635+
diagnoseAndRemoveAttr(attr, diag::attr_must_be_used_on_class_instance,
636+
attr->getAttrName());
637637
}
638638

639639
void AttributeChecker::visitGKInspectableAttr(GKInspectableAttr *attr) {
640640
// Only instance properties can be 'GKInspectable'.
641641
auto *VD = cast<VarDecl>(D);
642642
if (!VD->getDeclContext()->getSelfClassDecl() || VD->isStatic())
643-
diagnoseAndRemoveAttr(attr, diag::invalid_ibinspectable,
644-
attr->getAttrName());
643+
diagnoseAndRemoveAttr(attr, diag::attr_must_be_used_on_class_instance,
644+
attr->getAttrName());
645645
}
646646

647647
static Optional<Diag<bool,Type>>
@@ -690,7 +690,8 @@ void AttributeChecker::visitIBOutletAttr(IBOutletAttr *attr) {
690690
// Only instance properties can be 'IBOutlet'.
691691
auto *VD = cast<VarDecl>(D);
692692
if (!VD->getDeclContext()->getSelfClassDecl() || VD->isStatic())
693-
diagnoseAndRemoveAttr(attr, diag::invalid_iboutlet);
693+
diagnoseAndRemoveAttr(attr, diag::attr_must_be_used_on_class_instance,
694+
attr->getAttrName());
694695

695696
if (!VD->isSettable(nullptr)) {
696697
// Allow non-mutable IBOutlet properties in module interfaces,

test/attr/attr_iboutlet.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import Foundation
55

66
// expected-error@+1 {{@IBOutlet property cannot have non-object type 'Int'}}
7-
@IBOutlet // expected-error {{only instance properties can be declared @IBOutlet}} {{1-11=}}
7+
@IBOutlet // expected-error {{only class instance properties can be declared @IBOutlet}} {{1-11=}}
88
var iboutlet_global: Int?
99

1010
@IBOutlet // expected-error {{@IBOutlet may only be used on 'var' declarations}} {{1-11=}}
@@ -22,7 +22,7 @@ class IBOutletWrapperTy {
2222

2323
@IBOutlet
2424
class var staticValue: IBOutletWrapperTy? = 52 // expected-error {{cannot convert value of type 'Int' to specified type 'IBOutletWrapperTy?'}}
25-
// expected-error@-2 {{only instance properties can be declared @IBOutlet}} {{3-12=}}
25+
// expected-error@-2 {{only class instance properties can be declared @IBOutlet}} {{3-12=}}
2626
// expected-error@-2 {{class stored properties not supported}}
2727

2828
@IBOutlet // expected-error {{@IBOutlet may only be used on 'var' declarations}} {{3-13=}}

test/attr/attributes.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ class Inspect {
4040
@IBInspectable func foo() {} // expected-error {{@IBInspectable may only be used on 'var' declarations}} {{3-18=}}
4141
@GKInspectable func foo2() {} // expected-error {{@GKInspectable may only be used on 'var' declarations}} {{3-18=}}
4242

43-
@IBInspectable class var cval: Int { return 0 } // expected-error {{only instance properties can be declared @IBInspectable}} {{3-18=}}
44-
@GKInspectable class var cval2: Int { return 0 } // expected-error {{only instance properties can be declared @GKInspectable}} {{3-18=}}
43+
@IBInspectable class var cval: Int { return 0 } // expected-error {{only class instance properties can be declared @IBInspectable}} {{3-18=}}
44+
@GKInspectable class var cval2: Int { return 0 } // expected-error {{only class instance properties can be declared @GKInspectable}} {{3-18=}}
4545
}
46-
@IBInspectable var ibinspectable_global : Int // expected-error {{only instance properties can be declared @IBInspectable}} {{1-16=}}
47-
@GKInspectable var gkinspectable_global : Int // expected-error {{only instance properties can be declared @GKInspectable}} {{1-16=}}
46+
@IBInspectable var ibinspectable_global : Int // expected-error {{only class instance properties can be declared @IBInspectable}} {{1-16=}}
47+
@GKInspectable var gkinspectable_global : Int // expected-error {{only class instance properties can be declared @GKInspectable}} {{1-16=}}
4848

49+
struct inspectableWithStruct {
50+
@IBInspectable var IBInspectableInStruct: Int // expected-error {{only class instance properties can be declared @IBInspectable}} {{3-18=}}
51+
@GKInspectable var GKInspectableInStruct: Int // expected-error {{only class instance properties can be declared @GKInspectable}} {{3-18=}}
52+
}
4953

5054
func foo(x: @convention(block) Int) {} // expected-error {{@convention attribute only applies to function types}}
5155
func foo(x: @convention(block) (Int) -> Int) {}

0 commit comments

Comments
 (0)