Skip to content

Commit 570878c

Browse files
committed
Change message of invalid_ibinspectable, remove hardcoded invalid_iboutlet error and instead use non-hardcoded invalid_ibinspectable
1 parent f387076 commit 570878c

File tree

5 files changed

+18
-16
lines changed

5 files changed

+18
-16
lines changed

include/swift/AST/DiagnosticsSema.def

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

1409-
ERROR(invalid_iboutlet,none,
1410-
"only instance properties can be declared @IBOutlet", ())
14111409
ERROR(iboutlet_nonobjc_class,none,
14121410
"@IBOutlet property cannot %select{have|be an array of}0 "
14131411
"non-'@objc' class type %1", (bool, Type))
@@ -1429,8 +1427,8 @@ NOTE(note_make_implicitly_unwrapped_optional,none,
14291427
ERROR(invalid_ibdesignable_extension,none,
14301428
"@IBDesignable can only be applied to classes and extensions "
14311429
"of classes", ())
1432-
ERROR(invalid_ibinspectable,none,
1433-
"only instance properties can be declared @%0", (StringRef))
1430+
ERROR(attr_must_be_used_on_class_instance,none,
1431+
"only class instance properties can be declared @%0", (StringRef))
14341432
ERROR(invalid_ibaction_decl,none,
14351433
"only instance methods can be declared @%0", (StringRef))
14361434
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,15 @@ 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,
635+
diagnoseAndRemoveAttr(attr, diag::attr_must_be_used_on_class_instance,
636636
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,
643+
diagnoseAndRemoveAttr(attr, diag::attr_must_be_used_on_class_instance,
644644
attr->getAttrName());
645645
}
646646

@@ -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)