aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-12-21 11:53:44 +0000
committergingerBill <gingerBill@users.noreply.github.com>2025-12-21 11:53:44 +0000
commitd139c72fc24fdb574861ac22fc11b91de944b2a4 (patch)
treee6bdc024d3736998d7830bd7fc9c086676dd3fbf /src
parente138e76f21532527726897421b139fde9d05e7ce (diff)
Make `using` as a statement an opt-in with `#+feature using-stmt`
Diffstat (limited to 'src')
-rw-r--r--src/build_settings.cpp5
-rw-r--r--src/check_stmt.cpp8
-rw-r--r--src/check_type.cpp11
-rw-r--r--src/parser.cpp2
4 files changed, 19 insertions, 7 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp
index 7160f3721..12631c403 100644
--- a/src/build_settings.cpp
+++ b/src/build_settings.cpp
@@ -360,6 +360,8 @@ enum OptInFeatureFlags : u64 {
OptInFeatureFlag_IntegerDivisionByZero_Self = 1u<<4,
OptInFeatureFlag_IntegerDivisionByZero_AllBits = 1u<<5,
+ OptInFeatureFlag_UsingStmt = 1u<<6,
+
OptInFeatureFlag_IntegerDivisionByZero_ALL = OptInFeatureFlag_IntegerDivisionByZero_Trap|
OptInFeatureFlag_IntegerDivisionByZero_Zero|
@@ -384,6 +386,9 @@ u64 get_feature_flag_from_name(String const &name) {
if (name == "integer-division-by-zero:all-bits") {
return OptInFeatureFlag_IntegerDivisionByZero_AllBits;
}
+ if (name == "using-stmt") {
+ return OptInFeatureFlag_UsingStmt;
+ }
if (name == "global-context") {
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 835f0162a..26860db4f 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -2943,10 +2943,12 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
error(us->token, "Empty 'using' list");
return;
}
- if (check_vet_flags(node) & VetFlag_UsingStmt) {
+
+ u64 feature_flags = check_feature_flags(ctx, node);
+ if ((feature_flags & OptInFeatureFlag_UsingStmt) == 0) {
ERROR_BLOCK();
- error(node, "'using' as a statement is not allowed when '-vet' or '-vet-using' is applied");
- error_line("\t'using' is considered bad practice to use as a statement outside of immediate refactoring\n");
+ error(node, "'using' has been disallowed as it is considered bad practice to use as a statement outside of immediate refactoring");
+ error_line("\tIt you do require it for refactoring purposes or legacy code, it can be enabled on a per-file basis with '#+feature using-stmt'\n");
}
for (Ast *expr : us->list) {
diff --git a/src/check_type.cpp b/src/check_type.cpp
index af07efd8f..2452cc6d0 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -1830,11 +1830,14 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
Type *specialization = nullptr;
bool is_using = (p->flags&FieldFlag_using) != 0;
- if ((check_vet_flags(param) & VetFlag_UsingParam) && is_using) {
- ERROR_BLOCK();
- error(param, "'using' on a procedure parameter is not allowed when '-vet' or '-vet-using-param' is applied");
- error_line("\t'using' is considered bad practice to use as a statement/procedure parameter outside of immediate refactoring\n");
+
+ u64 feature_flags = check_feature_flags(ctx, param);
+
+ if (is_using && (feature_flags & OptInFeatureFlag_UsingStmt) == 0) {
+ ERROR_BLOCK();
+ error(param, "'using' has been disallowed as it is considered bad practice to use as a statement/procedure parameter outside of immediate refactoring");
+ error_line("\tIt you do require it for refactoring purposes or legacy code, it can be enabled on a per-file basis with '#+feature using-stmt'\n");
}
if (type_expr == nullptr) {
diff --git a/src/parser.cpp b/src/parser.cpp
index 06703d643..e27e184d0 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -6449,6 +6449,8 @@ gb_internal u64 parse_feature_tag(Token token_for_pos, String s) {
syntax_error(token_for_pos, "Invalid feature flag name: %.*s", LIT(p));
error_line("\tExpected one of the following\n");
error_line("\tdynamic-literals\n");
+ error_line("\tglobal-context\n");
+ error_line("\tusing-stmt\n");
error_line("\tinteger-division-by-zero:trap\n");
error_line("\tinteger-division-by-zero:zero\n");
error_line("\tinteger-division-by-zero:self\n");