aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2026-01-30 11:00:18 +0000
committerGitHub <noreply@github.com>2026-01-30 11:00:18 +0000
commitc4952c0b7e91e4e10195593e322c1259d2c9ab33 (patch)
tree247c11fd63a68d31e8c4e603df7372b4b90a43a5
parent5d47a2e92dc1e919124af6fceb740830b6ea6886 (diff)
parent19b545e7cb0b09a7c8b3424ca8276b9e37f8de80 (diff)
Merge pull request #6048 from odin-lang/bill/feature-using-stmt
Make `using` as a statement opt-in with `#+feature using-stmt`
-rw-r--r--core/compress/zlib/zlib.odin2
-rw-r--r--core/image/netpbm/netpbm.odin34
-rw-r--r--core/image/png/png.odin2
-rw-r--r--core/thread/thread_other.odin2
-rw-r--r--examples/demo/demo.odin1
-rw-r--r--src/build_settings.cpp7
-rw-r--r--src/check_stmt.cpp8
-rw-r--r--src/check_type.cpp11
-rw-r--r--src/parser.cpp2
-rw-r--r--vendor/fontstash/fontstash.odin2
10 files changed, 39 insertions, 32 deletions
diff --git a/core/compress/zlib/zlib.odin b/core/compress/zlib/zlib.odin
index b9189c1f1..e484a4958 100644
--- a/core/compress/zlib/zlib.odin
+++ b/core/compress/zlib/zlib.odin
@@ -1,4 +1,4 @@
-#+vet !using-param
+#+feature using-stmt
package compress_zlib
/*
diff --git a/core/image/netpbm/netpbm.odin b/core/image/netpbm/netpbm.odin
index 25e0228b5..6a30d135a 100644
--- a/core/image/netpbm/netpbm.odin
+++ b/core/image/netpbm/netpbm.odin
@@ -1,4 +1,3 @@
-#+vet !using-stmt
package netpbm
import "core:bytes"
@@ -73,8 +72,7 @@ save_to_buffer :: proc(img: ^Image, custom_info: Info = {}, allocator := context
}
}
- // using info so we can just talk about the header
- using info
+ header := &info.header
// validation
if header.format in (PBM + PGM + Formats{.Pf}) && img.channels != 1 \
@@ -664,14 +662,14 @@ autoselect_pbm_format_from_image :: proc(img: ^Image, prefer_binary := true, for
ASCII :: Formats{.P1, .P2, .P3}
*/
- using res.header
+ h := &res.header
- width = img.width
- height = img.height
- channels = img.channels
- depth = img.depth
- maxval = 255 if img.depth == 8 else 65535
- little_endian = true if ODIN_ENDIAN == .Little else false
+ h.width = img.width
+ h.height = img.height
+ h.channels = img.channels
+ h.depth = img.depth
+ h.maxval = 255 if img.depth == 8 else 65535
+ h.little_endian = ODIN_ENDIAN == .Little
// Assume we'll find a suitable format
ok = true
@@ -680,37 +678,37 @@ autoselect_pbm_format_from_image :: proc(img: ^Image, prefer_binary := true, for
case 1:
// Must be Portable Float Map
if img.depth == 32 {
- format = .Pf
+ h.format = .Pf
return
}
if force_black_and_white {
// Portable Bit Map
- format = .P4 if prefer_binary else .P1
- maxval = 1
+ h.format = .P4 if prefer_binary else .P1
+ h.maxval = 1
return
} else {
// Portable Gray Map
- format = .P5 if prefer_binary else .P2
+ h.format = .P5 if prefer_binary else .P2
return
}
case 3:
// Must be Portable Float Map
if img.depth == 32 {
- format = .PF
+ h.format = .PF
return
}
// Portable Pixel Map
- format = .P6 if prefer_binary else .P3
+ h.format = .P6 if prefer_binary else .P3
return
case:
// Portable Arbitrary Map
if img.depth == 8 || img.depth == 16 {
- format = .P7
- scale = pfm_scale
+ h.format = .P7
+ h.scale = pfm_scale
return
}
}
diff --git a/core/image/png/png.odin b/core/image/png/png.odin
index 1a7240bad..0170d3168 100644
--- a/core/image/png/png.odin
+++ b/core/image/png/png.odin
@@ -1,4 +1,4 @@
-#+vet !using-stmt
+#+feature using-stmt
package png
/*
diff --git a/core/thread/thread_other.odin b/core/thread/thread_other.odin
index dde2a8e48..878119cbd 100644
--- a/core/thread/thread_other.odin
+++ b/core/thread/thread_other.odin
@@ -37,7 +37,7 @@ _destroy :: proc(thread: ^Thread) {
unimplemented("core:thread procedure not supported on target")
}
-_terminate :: proc(using thread : ^Thread, exit_code: int) {
+_terminate :: proc(thread : ^Thread, exit_code: int) {
unimplemented("core:thread procedure not supported on target")
}
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin
index 1ea06d096..d4f0d9d4b 100644
--- a/examples/demo/demo.odin
+++ b/examples/demo/demo.odin
@@ -1,5 +1,6 @@
#+vet !using-stmt !using-param
#+feature dynamic-literals
+#+feature using-stmt
package main
import "core:fmt"
diff --git a/src/build_settings.cpp b/src/build_settings.cpp
index e66d46713..6b8fefa59 100644
--- a/src/build_settings.cpp
+++ b/src/build_settings.cpp
@@ -366,9 +366,7 @@ enum OptInFeatureFlags : u64 {
OptInFeatureFlag_IntegerDivisionByZero_AllBits,
OptInFeatureFlag_ForceTypeAssert = 1u<<6,
-
-
-
+ OptInFeatureFlag_UsingStmt = 1u<<7,
};
u64 get_feature_flag_from_name(String const &name) {
@@ -387,6 +385,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 == "force-type-assert") {
return OptInFeatureFlag_ForceTypeAssert;
}
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 2dc621a84..1f433df36 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -2945,10 +2945,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 41c5f48d1..b1d0045e9 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -1845,11 +1845,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 c14055275..360537ab7 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -6504,6 +6504,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");
diff --git a/vendor/fontstash/fontstash.odin b/vendor/fontstash/fontstash.odin
index 772e379f0..33e7b68de 100644
--- a/vendor/fontstash/fontstash.odin
+++ b/vendor/fontstash/fontstash.odin
@@ -1,5 +1,5 @@
// An Odin-native source port of [[ Fontstash ; https://github.com/memononen/fontstash ]].
-#+vet !using-param
+#+feature using-stmt
package fontstash
import "base:runtime"