From b96bfaae6c7e9e597232281f359b3daea4207bb7 Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Mon, 16 Dec 2024 15:14:45 +0200 Subject: [PATCH 1/2] add `unsafe_table_lookup` to AST serialization --- src/builtin/module_builtin_ast_serialize.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/builtin/module_builtin_ast_serialize.cpp b/src/builtin/module_builtin_ast_serialize.cpp index 7a7a62431..6e0de0472 100644 --- a/src/builtin/module_builtin_ast_serialize.cpp +++ b/src/builtin/module_builtin_ast_serialize.cpp @@ -2076,6 +2076,7 @@ namespace das { << value.macro_context_persistent_heap << value.macro_context_collect << value.rtti + << value.unsafe_table_lookup << value.relaxed_pointer_const << value.version_2_syntax << value.gen2_make_syntax From ae4d8cd9c69c890107d6d91d30a548adb8a656e4 Mon Sep 17 00:00:00 2001 From: Dima Granetchi Date: Mon, 16 Dec 2024 15:14:56 +0200 Subject: [PATCH 2/2] enhance linting for unused variables by adding access flag checks --- daslib/lint.das | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/daslib/lint.das b/daslib/lint.das index 31d9dd5c4..fc89b1bb5 100644 --- a/daslib/lint.das +++ b/daslib/lint.das @@ -82,13 +82,13 @@ class LintVisitor : AstVisitor if v.isAccessUnused self->lint_error("unused variable {v.name}: {describe(v._type)} (add an underscore prefix if you really need it)", v.at) return - if !v.access_flags.access_ref && !v.access_flags.access_pass && v.init != null && v.init |> is_expr_const() - self->lint_error("unused variable {v.name}: {describe(v._type)} (add an underscore prefix if you really need it)", v.at) + if !v.access_flags.access_ref && !v.access_flags.access_pass && v.init != null && v.init |> is_expr_const() && !v.access_flags.access_fold + self->lint_error("unused variable {v.name}: {describe(v._type)} (add an underscore prefix if you really need it) {v.access_flags}", v.at) return - if !v.access_flags.access_ref && !v.access_flags.access_pass && !v.access_flags.access_get && (v.init == null || v.init.flags.noSideEffects) + if !v.access_flags.access_ref && !v.access_flags.access_pass && !v.access_flags.access_get && (v.init == null || v.init.flags.noSideEffects) && !v.access_flags.access_fold self->lint_error("unused variable {v.name}: {describe(v._type)} (add an underscore prefix if you really need it)", v.at) return - if !v.access_flags.access_get && !v.access_flags.access_ref + if !v.access_flags.access_get && !v.access_flags.access_ref && (v.init == null) let sideEffects = (v.init != null && !v.init.flags.noSideEffects) if !sideEffects self->lint_error("variable {v.name}: {describe(v._type)} is never used", v.at)