aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarold Brenes <harold@hbrenes.com>2025-05-03 03:00:32 -0400
committerHarold Brenes <harold@hbrenes.com>2025-05-03 03:09:31 -0400
commit6d18560ca3054184d9bd97f280472d8cb5bb5081 (patch)
tree470cc25bc50b42002532e21296c38df27523b49b /src
parentcf3830a6a86de1923a53609a67bb0a8d6b70a6a9 (diff)
Move unconditionally exporting Objective-C methods to the right location
Diffstat (limited to 'src')
-rw-r--r--src/check_decl.cpp14
-rw-r--r--src/checker.cpp17
2 files changed, 13 insertions, 18 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index fc2edeb9e..84893d5c4 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -1000,7 +1000,7 @@ gb_internal String handle_link_name(CheckerContext *ctx, Token token, String lin
}
-gb_internal void check_objc_methods(CheckerContext *ctx, Entity *e, AttributeContext const &ac) {
+gb_internal void check_objc_methods(CheckerContext *ctx, Entity *e, AttributeContext &ac) {
if (!(ac.objc_name.len || ac.objc_is_class_method || ac.objc_type)) {
return;
}
@@ -1046,6 +1046,18 @@ gb_internal void check_objc_methods(CheckerContext *ctx, Entity *e, AttributeCon
} else if (proc.result_count > 1) {
error(e->token, "Objective-C method implementations may return at most 1 value");
} else {
+ // Always export unconditionally
+ // NOTE(harold): This means check_objc_methods() MUST be called before
+ // e->Procedure.is_export is set in check_proc_decl()!
+ if (ac.is_export) {
+ error(e->token, "Explicit export not allowed when @(objc_implement) is set. It set exported implicitly");
+ }
+ if (ac.link_name != "") {
+ error(e->token, "Explicit linkage not allowed when @(objc_implement) is set. It set to \"strong\" implicitly");
+ }
+
+ ac.is_export = true;
+ ac.linkage = STR_LIT("strong");
auto method = ObjcMethodData{ ac, e };
method.ac.objc_selector = ac.objc_selector != "" ? ac.objc_selector : ac.objc_name;
diff --git a/src/checker.cpp b/src/checker.cpp
index 62cffa788..1569814cc 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -3353,11 +3353,6 @@ gb_internal DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
ac->test = true;
return true;
} else if (name == "export") {
- if (ac->objc_is_implementation) { // TODO(harold): Remove from here, this needs to be checked after all attributes are set.
- error(value, "Setting @(export) explicitly is not allowed when @(objc_implement) is set. It is exported implicitly.");
- return false;
- }
-
ExactValue ev = check_decl_attribute_value(c, value);
if (ev.kind == ExactValue_Invalid) {
ac->is_export = true;
@@ -3369,12 +3364,6 @@ gb_internal DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
}
return true;
} else if (name == "linkage") {
-
- if (ac->objc_is_implementation) { // TODO(harold): Remove from here, this needs to be checked after all attributes are set.
- error(value, "Explicit linkage not allowed when @(objc_implement) is set. It is set implicitly");
- return false;
- }
-
ExactValue ev = check_decl_attribute_value(c, value);
if (ev.kind != ExactValue_String) {
error(value, "Expected either a string 'linkage'");
@@ -3695,12 +3684,6 @@ gb_internal DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
error(elem, "Expected a boolean value, or no value, for '%.*s'", LIT(name));
}
- // This implies exported, strongly linked
- if (ac->objc_is_implementation) {
- ac->is_export = true;
- ac->linkage = str_lit("strong");
- }
-
return true;
} else if (name == "objc_selector") {
ExactValue ev = check_decl_attribute_value(c, value);