From cd0338af4431c00cae51a64f6650c8a7ac62b10f Mon Sep 17 00:00:00 2001 From: Phoenix Himself Date: Fri, 4 Oct 2024 10:07:16 +0200 Subject: [PATCH] Change unsafe keywords to trust (#498) * feat(unsafe): change unsafe keywords to trust * Update make_executable.ab keep consistency * fix: add command flags --------- Co-authored-by: Daniele Scasciafratte --- CONTRIBUTING.md | 2 +- build.ab | 4 +-- grammar.ebnf | 8 ++--- setup/install.ab | 6 ++-- setup/uninstall.ab | 2 +- src/modules/command/modifier.rs | 28 +++++++++------ src/modules/condition/failed.rs | 6 ++-- src/modules/variable/mod.rs | 2 +- src/std/date.ab | 8 ++--- src/std/env.ab | 26 +++++++------- src/std/fs.ab | 8 ++--- src/std/http.ab | 6 ++-- src/std/math.ab | 8 ++--- src/std/text.ab | 36 +++++++++---------- src/tests/stdlib/change_owner.ab | 4 +-- src/tests/stdlib/confirm.ab | 10 +++--- src/tests/stdlib/create_dir.ab | 2 +- src/tests/stdlib/create_symbolic_link.ab | 6 ++-- src/tests/stdlib/date_add.ab | 2 +- src/tests/stdlib/date_compare.ab | 2 +- src/tests/stdlib/date_posix.ab | 2 +- src/tests/stdlib/dir_exist.ab | 4 +-- src/tests/stdlib/file_append.ab | 10 +++--- src/tests/stdlib/file_exist.ab | 6 ++-- src/tests/stdlib/file_read.ab | 8 ++--- src/tests/stdlib/file_write.ab | 8 ++--- src/tests/stdlib/get_env_var.ab | 8 ++--- src/tests/stdlib/input.ab | 6 ++-- src/tests/stdlib/input_hidden.ab | 6 ++-- src/tests/stdlib/load_env_file.ab | 8 ++--- src/tests/stdlib/make_executable.ab | 6 ++-- src/tests/stdlib/no_output/download.ab | 6 ++-- src/tests/stdlib/now.ab | 2 +- src/tests/stdlib/shell_constant_get.ab | 4 +-- src/tests/stdlib/shell_constant_set.ab | 4 +-- src/tests/stdlib/shell_isset.ab | 2 +- src/tests/stdlib/shell_unset.ab | 8 ++--- src/tests/stdlib/shell_var_get.ab | 4 +-- src/tests/stdlib/shell_var_set.ab | 4 +-- src/tests/validity/cd.ab | 2 +- src/tests/validity/chained_modifiers.ab | 6 ++-- .../validity/chained_modifiers_commands.ab | 6 ++-- .../validity/chained_modifiers_functions.ab | 6 ++-- src/tests/validity/mv.ab | 8 ++--- src/tests/validity/unsafe_function_call.ab | 2 +- .../validity/unsafe_unwraps_failable_type.ab | 2 +- src/tests/validity/variable_ref_command.ab | 2 +- .../variable_ref_function_invocation.ab | 4 +-- src/utils/context.rs | 6 ++-- test_files/str/trim.ab | 2 +- 50 files changed, 167 insertions(+), 161 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c59c36dd..f73fa239 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -126,7 +126,7 @@ use crate::modules::expression::expr::Expr; // Translate module is not included in Heraclitus prelude as it's leaving the backend up to developer use crate::translate::module::TranslateModule; // Metadata is the object that is carried when iterating over syntax tree. -// - `ParserMetadata` - it carries the necessary information about the current parsing context such as variables and functions that were declared up to this point, warning messages aggregated up to this point, information whether this syntax is declared in a loop, function, main block, unsafe scope etc. +// - `ParserMetadata` - it carries the necessary information about the current parsing context such as variables and functions that were declared up to this point, warning messages aggregated up to this point, information whether this syntax is declared in a loop, function, main block, trust scope etc. // `TranslateMetadata` - it carries the necessary information for translation such as wether we are in a silent scope, in an eval context or what indentation should be used. use crate::utils::{ParserMetadata, TranslateMetadata}; // Documentation module tells compiler what markdown content should it generate for this syntax module. This is irrelevent to our simple module so we will just return empty string. diff --git a/build.ab b/build.ab index 61e08037..0430acb0 100644 --- a/build.ab +++ b/build.ab @@ -1,10 +1,10 @@ // Check if such directory exists $test -f "Cargo.toml" > /dev/null$ failed { echo "Please run this command in the project root directory" - unsafe $exit 1$ + trust $exit 1$ } -unsafe { +trust { if status == 0 { // Recompile installer scripts $cargo run -- setup/install.ab setup/install.sh$ diff --git a/grammar.ebnf b/grammar.ebnf index 74645ff9..4a7162c6 100644 --- a/grammar.ebnf +++ b/grammar.ebnf @@ -29,7 +29,7 @@ TYPE = 'Text' | 'Num' | 'Bool' | 'Null'; UNARY_OP = '-' | 'not' ; BINARY_OP = '+' | '-' | '*' | '/' | '%' | 'and' | 'or' | '==' | '!=' | '<' | '<=' | '>' | '>=' ; SILENT_MOD = 'silent' ; -UNSAFE_MOD = 'unsafe' ; +TRUST_MOD = 'trust' ; VISIBILITY = 'pub' ; (* Identifier *) @@ -59,11 +59,11 @@ list = empty_list | full_list ; (* Command expression *) (* The ordering of command modifiers doesn't matter *) -command_modifier = SILENT_MOD, [ UNSAFE_MOD ] ; +command_modifier = SILENT_MOD, [ TRUST_MOD ] ; command_modifier_block = command_modifier, multiline_block ; command_base = '$', { ANY_CHAR | interpolation }, '$' ; command = [ SILENT_MOD ], command_base, [ failure_handler ] ; -command_unsafe = [ SILENT_MOD ], UNSAFE_MOD, command_base ; +command_trust = [ SILENT_MOD ], TRUST_MOD, command_base ; (* Operations *) binary_operation = expression , BINARY_OP , expression ; @@ -86,7 +86,7 @@ variable_set = identifier, variable_index?, '=', expression ; (* Function *) function_call = identifier, '(', [ expression, { ',', expression } ], ')' ; function_call_failed = [ SILENT_MOD ], function_call, failure_handler ; -function_call_unsafe = [ SILENT_MOD ], UNSAFE_MOD, function_call ; +function_call_trust = [ SILENT_MOD ], TRUST_MOD, function_call ; function_def = [ VISIBILITY ], 'fun', identifier, '(', [ identifier, { ',', identifier } ], ')', block ; function_def_typed = [ VISIBILITY ], 'fun', identifier, '(', [ identifier, ':', TYPE, { ',', identifier, ':', TYPE } ], ')', ':', TYPE, block ; diff --git a/setup/install.ab b/setup/install.ab index e87fe3b5..2763e95f 100644 --- a/setup/install.ab +++ b/setup/install.ab @@ -9,7 +9,7 @@ let target = "amber" let archive = "amber.tar.xz" let agent = has_failed("uname -a") then "unknown" - else unsafe $uname -a$ + else trust $uname -a$ echo "" @@ -33,7 +33,7 @@ main(args) { let bins_folder = get_bins_folder(user_only_install) // Check if such directory exists - unsafe $test -d "{place}"$ + trust $test -d "{place}"$ if status == 0 { echo "Amber already installed" @@ -134,7 +134,7 @@ main(args) { let nickname = input("Would you like to help improve Amber by sharing your OS info with our developer database? Enter your GitHub nickname (or any nickname) or type `no`:") if (nickname != "no") { // Send feedback to the server - unsafe silent $curl -G --data-urlencode "agent={agent}" --data-urlencode "nickname={nickname}" --data-urlencode "name=download" "https://amber-lang.com/api/visit"$ + trust silent $curl -G --data-urlencode "agent={agent}" --data-urlencode "nickname={nickname}" --data-urlencode "name=download" "https://amber-lang.com/api/visit"$ } // Send success message diff --git a/setup/uninstall.ab b/setup/uninstall.ab index d927c5f4..33d00737 100644 --- a/setup/uninstall.ab +++ b/setup/uninstall.ab @@ -11,7 +11,7 @@ main(args) { let place = get_place(user_only_install) let bins_folder = get_bins_folder(user_only_install) - unsafe $test -d "{place}" > /dev/null$ + trust $test -d "{place}" > /dev/null$ if status == 0 { let sudo = user_only_install then "" else "sudo" diff --git a/src/modules/command/modifier.rs b/src/modules/command/modifier.rs index 1a1ec603..e04f9770 100644 --- a/src/modules/command/modifier.rs +++ b/src/modules/command/modifier.rs @@ -10,7 +10,7 @@ use crate::utils::metadata::{ParserMetadata, TranslateMetadata}; pub struct CommandModifier { pub block: Box, pub is_block: bool, - pub is_unsafe: bool, + pub is_trust: bool, pub is_silent: bool } @@ -23,14 +23,14 @@ impl CommandModifier { pub fn use_modifiers( &mut self, meta: &mut ParserMetadata, context: F ) -> SyntaxResult where F: FnOnce(&mut Self, &mut ParserMetadata) -> SyntaxResult { - let mut is_unsafe_holder = self.is_unsafe; - if self.is_unsafe { - swap(&mut is_unsafe_holder, &mut meta.context.is_unsafe_ctx); + let mut is_trust_holder = self.is_trust; + if self.is_trust { + swap(&mut is_trust_holder, &mut meta.context.is_trust_ctx); } let result = context(self, meta); // Swap back the value - if self.is_unsafe { - swap(&mut is_unsafe_holder, &mut meta.context.is_unsafe_ctx); + if self.is_trust { + swap(&mut is_trust_holder, &mut meta.context.is_trust_ctx); } result } @@ -40,11 +40,17 @@ impl CommandModifier { match meta.get_current_token() { Some(tok) => { match tok.word.as_str() { - "unsafe" => { - if self.is_unsafe { - return error!(meta, Some(tok.clone()), "You already declared `unsafe` modifier before"); + trust @ ("trust" | "unsafe") => { + if trust == "unsafe" { + let message = Message::new_warn_at_token(meta, Some(tok.clone())) + .message("The keyword `unsafe` has been deprecated in favor of `trust`.") + .comment("Learn more about this change: https://docs.amber-lang.com/basic_syntax/commands#command-modifiers"); + meta.add_message(message); } - self.is_unsafe = true; + if self.is_trust { + return error!(meta, Some(tok.clone()), "You already declared `trust` modifier before"); + } + self.is_trust = true; meta.increment_index(); }, "silent" => { @@ -71,7 +77,7 @@ impl SyntaxModule for CommandModifier { CommandModifier { block: Box::new(Block::new()), is_block: true, - is_unsafe: false, + is_trust: false, is_silent: false } } diff --git a/src/modules/condition/failed.rs b/src/modules/condition/failed.rs index 18fd3116..c8b0b045 100644 --- a/src/modules/condition/failed.rs +++ b/src/modules/condition/failed.rs @@ -27,7 +27,7 @@ impl SyntaxModule for Failed { fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult { let tok = meta.get_current_token(); if token(meta, "?").is_ok() { - if !meta.context.is_fun_ctx && !meta.context.is_main_ctx && !meta.context.is_unsafe_ctx { + if !meta.context.is_fun_ctx && !meta.context.is_main_ctx && !meta.context.is_trust_ctx { return error!(meta, tok, "The '?' operator can only be used in the main block or function body") } self.is_question_mark = true; @@ -40,7 +40,7 @@ impl SyntaxModule for Failed { if self.block.is_empty() { let message = Message::new_warn_at_token(meta, tok) .message("Empty failed block") - .comment("You should use 'unsafe' modifier to run commands without handling errors"); + .comment("You should use 'trust' modifier to run commands without handling errors"); meta.add_message(message); } token(meta, "}")?; @@ -56,7 +56,7 @@ impl SyntaxModule for Failed { } } }, - Err(_) => if meta.context.is_unsafe_ctx { + Err(_) => if meta.context.is_trust_ctx { self.is_main = meta.context.is_main_ctx; self.is_parsed = true; return Ok(()); diff --git a/src/modules/variable/mod.rs b/src/modules/variable/mod.rs index 51bab21a..742cdd77 100644 --- a/src/modules/variable/mod.rs +++ b/src/modules/variable/mod.rs @@ -30,7 +30,7 @@ pub fn variable_name_keywords() -> Vec<&'static str> { // Types "Text", "Number", "Bool", "Null", // Command Modifiers - "silent", "unsafe", + "silent", "trust", // Misc "echo", "status", "nameof", "mv", "cd", "exit", ] diff --git a/src/std/date.ab b/src/std/date.ab index 6f33f3bd..0eeb59ae 100644 --- a/src/std/date.ab +++ b/src/std/date.ab @@ -70,7 +70,7 @@ /// ``` pub fun date_posix(format: Text = "", date: Text = "", utc: Bool = false): Text? { if format == "": format = "%FT%T%Z" - if date == "": date = unsafe $date +"%FT%T%Z"$ + if date == "": date = trust $date +"%FT%T%Z"$ if (utc) { return $date --utc -d "{date}" +"{format}"$? } else { @@ -81,7 +81,7 @@ pub fun date_posix(format: Text = "", date: Text = "", utc: Bool = false): Text? /// Returns the current timestamp (seconds since the Epoch (1970-01-01 00:00 UTC)). #[allow_absurd_cast] pub fun now(): Num { - return unsafe $date +%s$ as Num + return trust $date +%s$ as Num } /// ### EXPERIMENTAL @@ -101,7 +101,7 @@ pub fun now(): Num { /// - minutes /// - seconds pub fun date_add(add:Text, date:Text = "", utc: Bool = false): Text? { - if date == "": date = unsafe $date +"%FT%T%Z"$ + if date == "": date = trust $date +"%FT%T%Z"$ return date_posix("", "{date_posix("%F", date, utc)?} {add} {date_posix("%T", date, utc)?}", utc)? } @@ -117,7 +117,7 @@ pub fun date_add(add:Text, date:Text = "", utc: Bool = false): Text? { /// If date_b is not provided, current date will be used. #[allow_absurd_cast] pub fun date_compare(date_a: Text, date_b: Text = "", utc: Bool = false): Num? { - if date_b == "": date_b = unsafe date_posix("", "", utc) + if date_b == "": date_b = trust date_posix("", "", utc) let timestamp_a = date_posix("%s", date_a, utc)? as Num let timestamp_b = date_posix("%s", date_b, utc)? as Num if timestamp_a > timestamp_b: return 1 diff --git a/src/std/env.ab b/src/std/env.ab index dbea4c12..9b188559 100644 --- a/src/std/env.ab +++ b/src/std/env.ab @@ -3,14 +3,14 @@ import * from "std/text" /// Retrieves the value of an environment variable, optionally sourcing it from a file if not already set. pub fun get_env_var(var: Text, file: Text = ".env"): Text { - let _var = unsafe $echo "\$\{!var}"$ + let _var = trust $echo "\$\{!var}"$ if _var != "" { return _var } if file_exist(file) { - unsafe $source "{file}"$ - return unsafe $echo "\$\{!var}"$ + trust $source "{file}"$ + return trust $echo "\$\{!var}"$ } return "" @@ -18,7 +18,7 @@ pub fun get_env_var(var: Text, file: Text = ".env"): Text { /// Loads the env file in the environment, using `xargs`. pub fun load_env_file(file: Text = ".env"): Null { - unsafe $export "\$(xargs < {file})" > /dev/null$ + trust $export "\$(xargs < {file})" > /dev/null$ } /// Checks if a variable inside the shell session exists. @@ -64,13 +64,13 @@ pub fun is_command(command: Text): Bool { /// Creates a prompt and returns the value. pub fun input(prompt: Text): Text { - unsafe $read -p "\${nameof prompt}"$ + trust $read -p "\${nameof prompt}"$ return "\$REPLY" } /// Creates a prompt, hides any user input and returns the value. pub fun input_hidden(prompt: Text): Text { - unsafe { + trust { $read -s -p "\${nameof prompt}"$ $echo "" >&2$ } @@ -82,24 +82,24 @@ pub fun input_hidden(prompt: Text): Text { /// "No" is the default choice, set default_yes to true for "Yes" as default choice. pub fun confirm(prompt: Text, default_yes: Bool = false): Bool { let choice_default = default_yes then " [\x1b[1mY/\x1b[0mn]" else " [y/\x1b[1mN\x1b[0m]" - unsafe { + trust { $printf "\x1b[1m{prompt}\x1b[0m{choice_default}"$ $read -s -n 1$ $printf "\n"$ } - let result = lower(unsafe $echo \$REPLY$) + let result = lower(trust $echo \$REPLY$) return result == "y" or (result == "" and default_yes) } /// Checks if the command has failed. pub fun has_failed(command: Text): Bool { - unsafe silent $eval {command}$ + trust silent $eval {command}$ return status != 0 } /// Checks if the script is running with a user with root permission. pub fun is_root(): Bool { - if unsafe $id -u$ == "0" { + if trust $id -u$ == "0" { return true } @@ -108,13 +108,13 @@ pub fun is_root(): Bool { /// `printf` the text following the arguments. pub fun printf(format: Text, args: [Text] = [""]): Null { - unsafe ${nameof args}=("{format}" "\$\{{nameof args}[@]}")$ - unsafe $printf "\$\{{nameof args}[@]}"$ + trust ${nameof args}=("{format}" "\$\{{nameof args}[@]}")$ + trust $printf "\$\{{nameof args}[@]}"$ } /// Escapes the text to be used with `printf`. pub fun printf_escape(text: Text): Text { - return unsafe $echo \${nameof text} | sed -e 's/\\\\/\\\\\\\\/g' -e "s/%/%%/g"$ + return trust $echo \${nameof text} | sed -e 's/\\\\/\\\\\\\\/g' -e "s/%/%%/g"$ } /// Prepares a text with formatting options for `printf`. diff --git a/src/std/fs.ab b/src/std/fs.ab index 2b8b048c..560ffaca 100644 --- a/src/std/fs.ab +++ b/src/std/fs.ab @@ -37,7 +37,7 @@ pub fun file_append(path, content) { /// If the file doesn't exist, it returns a boolean and prints a message. pub fun create_symbolic_link(origin: Text, destination: Text): Bool { if file_exist(origin) { - unsafe $ln -s "{origin}" "{destination}"$ + trust $ln -s "{origin}" "{destination}"$ return true } @@ -48,7 +48,7 @@ pub fun create_symbolic_link(origin: Text, destination: Text): Bool { /// Creates a directory with all parent directories as required. pub fun create_dir(path: Text): Null { if not dir_exist(path) { - unsafe $mkdir -p "{path}"$ + trust $mkdir -p "{path}"$ } } @@ -57,7 +57,7 @@ pub fun create_dir(path: Text): Null { /// If the file doesn't exist, it returns a boolean and prints a message. pub fun make_executable(path: Text): Bool { if file_exist(path) { - unsafe $chmod +x "{path}"$ + trust $chmod +x "{path}"$ return true } @@ -70,7 +70,7 @@ pub fun make_executable(path: Text): Bool { /// If the file doesn't exist, it returns `false` pub fun change_owner(user: Text, path: Text): Bool { if file_exist(path) or dir_exist(path) { - unsafe $chown -R "{user}" "{path}"$ + trust $chown -R "{user}" "{path}"$ return true } diff --git a/src/std/http.ab b/src/std/http.ab index 17f3348e..f2978b42 100644 --- a/src/std/http.ab +++ b/src/std/http.ab @@ -7,13 +7,13 @@ import * from "std/env" pub fun download(url: Text, path: Text): Bool { if { is_command("curl") { - unsafe $curl -L -o "{path}" "{url}"$ + trust $curl -L -o "{path}" "{url}"$ } is_command("wget") { - unsafe $wget "{url}" -P "{path}"$ + trust $wget "{url}" -P "{path}"$ } is_command("aria2c") { - unsafe $aria2c "{url}" -d "{path}"$ + trust $aria2c "{url}" -d "{path}"$ } else { return false diff --git a/src/std/math.ab b/src/std/math.ab index d24f6b26..e08b8e3c 100644 --- a/src/std/math.ab +++ b/src/std/math.ab @@ -1,23 +1,23 @@ /// Sums an array's contents #[allow_absurd_cast] pub fun sum(list: [Num]): Num { - return unsafe $echo "{list}" | awk '\{s=0; for (i=1; i<=NF; i++) s+=\$i; print s}'$ as Num + return trust $echo "{list}" | awk '\{s=0; for (i=1; i<=NF; i++) s+=\$i; print s}'$ as Num } /// Returns a number, rounded to the nearest integer #[allow_absurd_cast] pub fun round(number: Num): Num { if number > 0 { - return unsafe $echo "({number}+0.5)/1" | bc$ as Num + return trust $echo "({number}+0.5)/1" | bc$ as Num } - return unsafe $echo "({number}-0.5)/1" | bc$ as Num + return trust $echo "({number}-0.5)/1" | bc$ as Num } /// Returns the largest integer less than or equal to a number #[allow_absurd_cast] pub fun floor(number: Num): Num { - return unsafe $echo "{number}" | awk '\{printf "%d", (\$1 < 0 ? int(\$1) - 1 : int(\$1))}'$ as Num + return trust $echo "{number}" | awk '\{printf "%d", (\$1 < 0 ? int(\$1) - 1 : int(\$1))}'$ as Num } /// Returns the smallest integer greater than or equal to a number diff --git a/src/std/text.ab b/src/std/text.ab index da7a06c4..fd4d25e8 100644 --- a/src/std/text.ab +++ b/src/std/text.ab @@ -12,7 +12,7 @@ pub fun replace_once(source, search, replace) { /// /// Function uses `sed` pub fun replace_regex(source: Text, search: Text, replace: Text, extended: Bool = false): Text { - unsafe { + trust { search = replace(search, "/", "\/") replace = replace(replace, "/", "\/") if extended { @@ -31,7 +31,7 @@ pub fun replace_regex(source: Text, search: Text, replace: Text, extended: Bool /// Splits the input `text` into an array of substrings using the specified `delimiter`. pub fun split(text: Text, delimiter: Text): [Text] { let result = [Text] - unsafe $IFS="{delimiter}" read -rd '' -a {nameof result} < <(printf %s "\${nameof text}")$ + trust $IFS="{delimiter}" read -rd '' -a {nameof result} < <(printf %s "\${nameof text}")$ return result } @@ -47,17 +47,17 @@ pub fun words(text: Text): [Text] { /// Merges text using the delimeter specified. pub fun join(list: [Text], delimiter: Text): Text { - return unsafe $IFS="{delimiter}" ; echo "\$\{{nameof list}[*]}"$ + return trust $IFS="{delimiter}" ; echo "\$\{{nameof list}[*]}"$ } /// Trims the spaces at top of the text using `sed`. pub fun trim_left(text: Text): Text { - return unsafe $echo "{text}" | sed -e 's/^[[:space:]]*//'$ + return trust $echo "{text}" | sed -e 's/^[[:space:]]*//'$ } /// Trims the spaces at end of the text using `sed`. pub fun trim_right(text: Text): Text { - return unsafe $echo "{text}" | sed -e 's/[[:space:]]*\$//'$ + return trust $echo "{text}" | sed -e 's/[[:space:]]*\$//'$ } /// Trims the spaces from the text input. @@ -67,12 +67,12 @@ pub fun trim(text: Text): Text { /// Makes the text input lowercase using `tr`. pub fun lower(text: Text): Text { - return unsafe $echo "{text}" | tr '[:upper:]' '[:lower:]'$ + return trust $echo "{text}" | tr '[:upper:]' '[:lower:]'$ } /// Makes the text input uppercase using `tr`. pub fun upper(text: Text): Text { - return unsafe $echo "{text}" | tr '[:lower:]' '[:upper:]'$ + return trust $echo "{text}" | tr '[:lower:]' '[:upper:]'$ } /// Attempts to parse a given text into a number, returning the parsed number or zero if parsing fails. @@ -85,7 +85,7 @@ pub fun parse(text: Text): Num? { /// Splits a text into an array of individual characters. pub fun chars(text: Text): [Text] { let chars = [Text] - unsafe $for ((i=0; i<\$\{#{nameof text}}; i++)); do + trust $for ((i=0; i<\$\{#{nameof text}}; i++)); do {nameof chars}+=( "\$\{{nameof text}:\$i:1}" ); done;$ return chars @@ -94,7 +94,7 @@ pub fun chars(text: Text): [Text] { /// Gets the length of provided text or array. #[allow_absurd_cast] pub fun len(value): Num { - unsafe { + trust { if value is Text: return $echo "\$\{#{nameof value}}"$ as Num else: @@ -104,7 +104,7 @@ pub fun len(value): Num { /// Checks if some text contains a value/ pub fun contains(text: Text, phrase: Text): Bool { - let result = unsafe $if [[ "{text}" == *"{phrase}"* ]]; then + let result = trust $if [[ "{text}" == *"{phrase}"* ]]; then echo 1 fi$ @@ -113,12 +113,12 @@ pub fun contains(text: Text, phrase: Text): Bool { /// Reverses text using `rev`. pub fun reverse(text: Text): Text { - return unsafe $echo "{text}" | rev$ + return trust $echo "{text}" | rev$ } /// Checks if text starts with a value. pub fun starts_with(text: Text, prefix: Text): Bool { - let result = unsafe $if [[ "{text}" == "{prefix}"* ]]; then + let result = trust $if [[ "{text}" == "{prefix}"* ]]; then echo 1 fi$ @@ -127,7 +127,7 @@ pub fun starts_with(text: Text, prefix: Text): Bool { /// Checks if text ends with a value. pub fun ends_with(text: Text, suffix: Text): Bool { - let result = unsafe $if [[ "{text}" == *"{suffix}" ]]; then + let result = trust $if [[ "{text}" == *"{suffix}" ]]; then echo 1 fi$ @@ -142,26 +142,26 @@ pub fun ends_with(text: Text, suffix: Text): Bool { pub fun slice(text: Text, index: Num, length: Num = 0): Text { if length == 0: length = len(text) - index if length <= 0: return "" - return unsafe $printf "%.{length}s" "\$\{text:{index}}"$ + return trust $printf "%.{length}s" "\$\{text:{index}}"$ } /// Returns the character from `text` at the specified `index` (0-based). /// /// If `index` is negative, the substring starts from the end of `text` based on the absolute value of `index`. pub fun char_at(text: Text, index: Num): Text { - return unsafe $printf "%.1s" "\$\{text:{index}}"$ + return trust $printf "%.1s" "\$\{text:{index}}"$ } /// Capitalize the first letter of the given `text`. pub fun capitalize(text: Text): Text { - return unsafe $echo "{text}" | sed "s/^\(.\)/\U\1/"$ + return trust $echo "{text}" | sed "s/^\(.\)/\U\1/"$ } /// Pads `text` with the specified `pad` character on left until it reaches the desired `length`. pub fun lpad(text: Text, pad: Text, length: Num): Text { if length <= len(text): return text length = len(text) - length - pad = unsafe $printf "%{length}s" "" | tr " " "{pad}"$ + pad = trust $printf "%{length}s" "" | tr " " "{pad}"$ return pad + text } @@ -169,7 +169,7 @@ pub fun lpad(text: Text, pad: Text, length: Num): Text { pub fun rpad(text: Text, pad: Text, length: Num): Text { if length <= len(text): return text length = len(text) - length - pad = unsafe $printf "%{length}s" "" | tr " " "{pad}"$ + pad = trust $printf "%{length}s" "" | tr " " "{pad}"$ return text + pad } diff --git a/src/tests/stdlib/change_owner.ab b/src/tests/stdlib/change_owner.ab index 5535c30b..ef563658 100644 --- a/src/tests/stdlib/change_owner.ab +++ b/src/tests/stdlib/change_owner.ab @@ -7,10 +7,10 @@ main { $touch {tmpdir}/amber-symbolic$ failed { echo "It wasn't possible to create {tmpdir}/amber-symbolic" } - if change_owner(unsafe $whoami$, "{tmpdir}/amber-symbolic") { + if change_owner(trust $whoami$, "{tmpdir}/amber-symbolic") { echo "Succeded" } else { echo "File {tmpdir}/amber-symbolic not exists" } - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/confirm.ab b/src/tests/stdlib/confirm.ab index 135059e6..cc10890a 100644 --- a/src/tests/stdlib/confirm.ab +++ b/src/tests/stdlib/confirm.ab @@ -1,11 +1,11 @@ import * from "std/env" main { - unsafe $echo "Y" > /tmp/test_confirm$ - unsafe $exec 0< /tmp/test_confirm$ + trust $echo "Y" > /tmp/test_confirm$ + trust $exec 0< /tmp/test_confirm$ if confirm("Yes"): echo "Confirm Yes" - unsafe $echo "N" > /tmp/test_confirm$ + trust $echo "N" > /tmp/test_confirm$ if not confirm("No"): echo "Confirm No" - unsafe $echo "" > /tmp/test_confirm$ + trust $echo "" > /tmp/test_confirm$ if confirm("Default", true): echo "Confirm Default" - unsafe $rm /tmp/test_confirm$ + trust $rm /tmp/test_confirm$ } diff --git a/src/tests/stdlib/create_dir.ab b/src/tests/stdlib/create_dir.ab index e39c7a3a..b007f188 100644 --- a/src/tests/stdlib/create_dir.ab +++ b/src/tests/stdlib/create_dir.ab @@ -2,7 +2,7 @@ import { create_dir, dir_exist } from "std/fs" main { create_dir("/tmp/amber-test") if dir_exist("/tmp/amber-test") { - unsafe $rm -fr /tmp/amber-test$ + trust $rm -fr /tmp/amber-test$ echo "Succeded" } } diff --git a/src/tests/stdlib/create_symbolic_link.ab b/src/tests/stdlib/create_symbolic_link.ab index de68e945..5835f6e1 100644 --- a/src/tests/stdlib/create_symbolic_link.ab +++ b/src/tests/stdlib/create_symbolic_link.ab @@ -1,11 +1,11 @@ import { create_symbolic_link } from "std/fs" main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $touch {tmpdir}/amber-symbolic$ + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $touch {tmpdir}/amber-symbolic$ if create_symbolic_link("{tmpdir}/amber-symbolic", "{tmpdir}/amber-symbolic-link") { echo "Succeded" } else { echo "failed" } - unsafe $rm -fr {tmpdir}$ + trust $rm {tmpdir}$ } diff --git a/src/tests/stdlib/date_add.ab b/src/tests/stdlib/date_add.ab index 6c8404b1..7935d325 100644 --- a/src/tests/stdlib/date_add.ab +++ b/src/tests/stdlib/date_add.ab @@ -1,5 +1,5 @@ import * from "std/date" main { - if unsafe date_add("+17 Days", "2009-02-07T09:46:40UTC", true) == "2009-02-24T09:46:40UTC": echo "Succeded" + if trust date_add("+17 Days", "2009-02-07T09:46:40UTC", true) == "2009-02-24T09:46:40UTC": echo "Succeded" } \ No newline at end of file diff --git a/src/tests/stdlib/date_compare.ab b/src/tests/stdlib/date_compare.ab index 04bca715..f5cf2568 100644 --- a/src/tests/stdlib/date_compare.ab +++ b/src/tests/stdlib/date_compare.ab @@ -1,5 +1,5 @@ import * from "std/date" main { - if (unsafe date_compare("2000-01-01") == -1 and unsafe date_compare("2100-01-01") == 1) : echo "Succeded" + if (trust date_compare("2000-01-01") == -1 and trust date_compare("2100-01-01") == 1) : echo "Succeded" } \ No newline at end of file diff --git a/src/tests/stdlib/date_posix.ab b/src/tests/stdlib/date_posix.ab index 1180f986..8d618768 100644 --- a/src/tests/stdlib/date_posix.ab +++ b/src/tests/stdlib/date_posix.ab @@ -1,5 +1,5 @@ import * from "std/date" main { - if unsafe date_posix("", "@1234000000", true) == "2009-02-07T09:46:40UTC": echo "Succeded" + if trust date_posix("", "@1234000000", true) == "2009-02-07T09:46:40UTC": echo "Succeded" } \ No newline at end of file diff --git a/src/tests/stdlib/dir_exist.ab b/src/tests/stdlib/dir_exist.ab index e558ab3b..e138006b 100644 --- a/src/tests/stdlib/dir_exist.ab +++ b/src/tests/stdlib/dir_exist.ab @@ -1,10 +1,10 @@ import * from "std/fs" main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ if dir_exist(tmpdir) { echo "Succeded" } else { echo "Not Found" } - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/file_append.ab b/src/tests/stdlib/file_append.ab index 2f5f6111..1cb09283 100644 --- a/src/tests/stdlib/file_append.ab +++ b/src/tests/stdlib/file_append.ab @@ -1,12 +1,12 @@ import * from "std/fs" main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $cd {tmpdir}$ - unsafe $touch test.txt$ - unsafe file_append("test.txt", "Succeded") + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $cd {tmpdir}$ + trust $touch test.txt$ + trust file_append("test.txt", "Succeded") let f = file_read("test.txt") failed { echo "Failed" } echo f - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/file_exist.ab b/src/tests/stdlib/file_exist.ab index 0bc188a6..c5cdf70f 100644 --- a/src/tests/stdlib/file_exist.ab +++ b/src/tests/stdlib/file_exist.ab @@ -1,11 +1,11 @@ import * from "std/fs" main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $touch {tmpdir}/test.txt$ + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $touch {tmpdir}/test.txt$ if file_exist("{tmpdir}/test.txt") { echo "Succeded" } else { echo "Not Found" } - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/file_read.ab b/src/tests/stdlib/file_read.ab index 470e0b66..011e45bf 100644 --- a/src/tests/stdlib/file_read.ab +++ b/src/tests/stdlib/file_read.ab @@ -1,11 +1,11 @@ import * from "std/fs" main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $cd {tmpdir}$ - unsafe file_write("test.txt", "Succeded") + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $cd {tmpdir}$ + trust file_write("test.txt", "Succeded") let f = file_read("test.txt") failed { echo "Failed" } echo f - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/file_write.ab b/src/tests/stdlib/file_write.ab index 470e0b66..011e45bf 100644 --- a/src/tests/stdlib/file_write.ab +++ b/src/tests/stdlib/file_write.ab @@ -1,11 +1,11 @@ import * from "std/fs" main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $cd {tmpdir}$ - unsafe file_write("test.txt", "Succeded") + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $cd {tmpdir}$ + trust file_write("test.txt", "Succeded") let f = file_read("test.txt") failed { echo "Failed" } echo f - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/get_env_var.ab b/src/tests/stdlib/get_env_var.ab index bb7cd116..cbca6046 100644 --- a/src/tests/stdlib/get_env_var.ab +++ b/src/tests/stdlib/get_env_var.ab @@ -1,11 +1,11 @@ import { get_env_var } from "std/env" import { file_write } from "std/fs" main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $cd {tmpdir}$ - unsafe file_write(".env", "TEST=1") + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $cd {tmpdir}$ + trust file_write(".env", "TEST=1") if get_env_var("TEST") == "1" { echo "Succeded" } - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/input.ab b/src/tests/stdlib/input.ab index 82179442..68472421 100644 --- a/src/tests/stdlib/input.ab +++ b/src/tests/stdlib/input.ab @@ -4,9 +4,9 @@ import * from "std/env" // Hello, Amber main { - unsafe $echo "Amber" >> /tmp/test_input$ - unsafe $exec 0< /tmp/test_input$ + trust $echo "Amber" >> /tmp/test_input$ + trust $exec 0< /tmp/test_input$ let name = input("Please enter your name:") echo "Hello, " + name - unsafe $rm /tmp/test_input$ + trust $rm /tmp/test_input$ } diff --git a/src/tests/stdlib/input_hidden.ab b/src/tests/stdlib/input_hidden.ab index 87ca700f..331d0be1 100644 --- a/src/tests/stdlib/input_hidden.ab +++ b/src/tests/stdlib/input_hidden.ab @@ -4,9 +4,9 @@ import * from "std/env" // Hello, Amber main { - unsafe $echo "Amber" >> /tmp/test_input$ - unsafe $exec 0< /tmp/test_input$ + trust $echo "Amber" >> /tmp/test_input$ + trust $exec 0< /tmp/test_input$ let name = input_hidden("Please enter your name:") echo "Hello, " + name - unsafe $rm /tmp/test_input$ + trust $rm /tmp/test_input$ } diff --git a/src/tests/stdlib/load_env_file.ab b/src/tests/stdlib/load_env_file.ab index 7ce1152d..ab12a6b0 100644 --- a/src/tests/stdlib/load_env_file.ab +++ b/src/tests/stdlib/load_env_file.ab @@ -5,12 +5,12 @@ import { file_write } from "std/fs" // yes main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $cd {tmpdir}$ - unsafe file_write(".env", "TEST=1") + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $cd {tmpdir}$ + trust file_write(".env", "TEST=1") load_env_file() if get_env_var("TEST") == "1" { echo "yes" } - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/make_executable.ab b/src/tests/stdlib/make_executable.ab index 73fee6ba..af4d7a13 100644 --- a/src/tests/stdlib/make_executable.ab +++ b/src/tests/stdlib/make_executable.ab @@ -4,10 +4,10 @@ import { make_executable } from "std/fs" // created main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $touch {tmpdir}/amber-symbolic$ + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $touch {tmpdir}/amber-symbolic$ if make_executable("{tmpdir}/amber-symbolic") { echo "created" } - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/no_output/download.ab b/src/tests/stdlib/no_output/download.ab index d2be6072..f6687b0a 100644 --- a/src/tests/stdlib/no_output/download.ab +++ b/src/tests/stdlib/no_output/download.ab @@ -1,12 +1,12 @@ import * from "std/http" import * from "std/fs" main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $cd {tmpdir}$ + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $cd {tmpdir}$ if download("http://127.0.0.1:8081/", "./test.txt") { if file_exist("./test.txt") { echo "ok" } } - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/stdlib/now.ab b/src/tests/stdlib/now.ab index e37a550d..f4fcd935 100644 --- a/src/tests/stdlib/now.ab +++ b/src/tests/stdlib/now.ab @@ -1,5 +1,5 @@ import * from "std/date" main { - if now() == (unsafe $date +%s$ as Num): echo "Succeded" + if now() == (trust $date +%s$ as Num): echo "Succeded" } \ No newline at end of file diff --git a/src/tests/stdlib/shell_constant_get.ab b/src/tests/stdlib/shell_constant_get.ab index 6b8efa0d..85b01359 100644 --- a/src/tests/stdlib/shell_constant_get.ab +++ b/src/tests/stdlib/shell_constant_get.ab @@ -1,5 +1,5 @@ import * from "std/env" main { - unsafe shell_constant_set("test_shell_constant_get", "Succeded") - unsafe $echo "\$test_shell_constant_get"$ + trust shell_constant_set("test_shell_constant_get", "Succeded") + trust $echo "\$test_shell_constant_get"$ } diff --git a/src/tests/stdlib/shell_constant_set.ab b/src/tests/stdlib/shell_constant_set.ab index a50d5dd5..53905925 100644 --- a/src/tests/stdlib/shell_constant_set.ab +++ b/src/tests/stdlib/shell_constant_set.ab @@ -1,8 +1,8 @@ import * from "std/env" main { - unsafe shell_constant_set("test_shell_constant_set", "Succe") + trust shell_constant_set("test_shell_constant_set", "Succe") let str = "" - str += unsafe $echo "\$test_shell_constant_set"$ + str += trust $echo "\$test_shell_constant_set"$ shell_constant_set("test_shell_constant_set", "Succe") failed { str += "ded" } diff --git a/src/tests/stdlib/shell_isset.ab b/src/tests/stdlib/shell_isset.ab index e35c3a80..aad63300 100644 --- a/src/tests/stdlib/shell_isset.ab +++ b/src/tests/stdlib/shell_isset.ab @@ -1,6 +1,6 @@ import * from "std/env" main { - unsafe $test_var_isset="test"$ + trust $test_var_isset="test"$ if shell_isset("test_var_isset") { echo "Succeded" } diff --git a/src/tests/stdlib/shell_unset.ab b/src/tests/stdlib/shell_unset.ab index ea6da22a..3f819f35 100644 --- a/src/tests/stdlib/shell_unset.ab +++ b/src/tests/stdlib/shell_unset.ab @@ -1,7 +1,7 @@ import * from "std/env" main { - unsafe shell_var_set("test_shell_unset", "Succeded") - unsafe $echo \$test_shell_unset$ - unsafe shell_unset("test_shell_unset") - unsafe $echo \$test_shell_unset$ + trust shell_var_set("test_shell_unset", "Succeded") + trust $echo \$test_shell_unset$ + trust shell_unset("test_shell_unset") + trust $echo \$test_shell_unset$ } diff --git a/src/tests/stdlib/shell_var_get.ab b/src/tests/stdlib/shell_var_get.ab index 43aa78b9..d4dc44be 100644 --- a/src/tests/stdlib/shell_var_get.ab +++ b/src/tests/stdlib/shell_var_get.ab @@ -1,5 +1,5 @@ import * from "std/env" main { - unsafe $export test_shell_var_get="Succeded"$ - echo unsafe shell_var_get("test_shell_var_get") + trust $export test_shell_var_get="Succeded"$ + echo trust shell_var_get("test_shell_var_get") } diff --git a/src/tests/stdlib/shell_var_set.ab b/src/tests/stdlib/shell_var_set.ab index c81dd45f..95de7b78 100644 --- a/src/tests/stdlib/shell_var_set.ab +++ b/src/tests/stdlib/shell_var_set.ab @@ -1,5 +1,5 @@ import * from "std/env" main { - unsafe shell_var_set("test_shell_var_set", "Succeded") - unsafe $echo \$test_shell_var_set$ + trust shell_var_set("test_shell_var_set", "Succeded") + trust $echo \$test_shell_var_set$ } diff --git a/src/tests/validity/cd.ab b/src/tests/validity/cd.ab index b58fba5e..e7be0690 100644 --- a/src/tests/validity/cd.ab +++ b/src/tests/validity/cd.ab @@ -2,4 +2,4 @@ // /tmp cd "/tmp/" -unsafe $pwd$ +trust $pwd$ diff --git a/src/tests/validity/chained_modifiers.ab b/src/tests/validity/chained_modifiers.ab index e8b066e4..4c641205 100644 --- a/src/tests/validity/chained_modifiers.ab +++ b/src/tests/validity/chained_modifiers.ab @@ -1,11 +1,11 @@ // Output // Hello World -unsafe silent { +trust silent { echo "Hello World" $non-existent command$ } // Test for expression -let _ = silent unsafe $non-existent command$ +let _ = silent trust $non-existent command$ // Test for single statement -silent unsafe $non-existent command$ +silent trust $non-existent command$ diff --git a/src/tests/validity/chained_modifiers_commands.ab b/src/tests/validity/chained_modifiers_commands.ab index be14de46..a63af99e 100644 --- a/src/tests/validity/chained_modifiers_commands.ab +++ b/src/tests/validity/chained_modifiers_commands.ab @@ -1,8 +1,8 @@ -unsafe silent { +trust silent { echo "Succeded" $non-existent command$ } // Test for expression -let _ = silent unsafe $non-existent command$ +let _ = silent trust $non-existent command$ // Test for single statement -silent unsafe $non-existent command$ +silent trust $non-existent command$ diff --git a/src/tests/validity/chained_modifiers_functions.ab b/src/tests/validity/chained_modifiers_functions.ab index 08f17085..cdeac9a8 100644 --- a/src/tests/validity/chained_modifiers_functions.ab +++ b/src/tests/validity/chained_modifiers_functions.ab @@ -11,9 +11,9 @@ fun bar() { echo "this should not appear" } -unsafe foo("one") -unsafe { +trust foo("one") +trust { foo("two") } -unsafe silent foo("this should not appear") +trust silent foo("this should not appear") silent bar() diff --git a/src/tests/validity/mv.ab b/src/tests/validity/mv.ab index eb4e63d1..f66eb5cd 100644 --- a/src/tests/validity/mv.ab +++ b/src/tests/validity/mv.ab @@ -1,12 +1,12 @@ import * from "std/fs" main { - let tmpdir = unsafe $mktemp -d /tmp/amber-XXXX$ - unsafe $touch {tmpdir}/a$ - unsafe mv "{tmpdir}/a" "{tmpdir}/b" + let tmpdir = trust $mktemp -d /tmp/amber-XXXX$ + trust $touch {tmpdir}/a$ + trust mv "{tmpdir}/a" "{tmpdir}/b" if file_exist("{tmpdir}/b") { echo "Succeded" } else { echo "Not Found" } - unsafe $rm -fr {tmpdir}$ + trust $rm -fr {tmpdir}$ } diff --git a/src/tests/validity/unsafe_function_call.ab b/src/tests/validity/unsafe_function_call.ab index a0900259..9c7baa17 100644 --- a/src/tests/validity/unsafe_function_call.ab +++ b/src/tests/validity/unsafe_function_call.ab @@ -7,5 +7,5 @@ fun safe_division(a: Num, b: Num): Num? { return a / b } -let result = unsafe safe_division(24, 4) +let result = trust safe_division(24, 4) echo "{result}, {status}" diff --git a/src/tests/validity/unsafe_unwraps_failable_type.ab b/src/tests/validity/unsafe_unwraps_failable_type.ab index e71acf8a..43dac273 100644 --- a/src/tests/validity/unsafe_unwraps_failable_type.ab +++ b/src/tests/validity/unsafe_unwraps_failable_type.ab @@ -6,4 +6,4 @@ fun test(): Num? { return 42 } -if unsafe test() is Num: echo "Succeded" +if trust test() is Num: echo "Succeded" diff --git a/src/tests/validity/variable_ref_command.ab b/src/tests/validity/variable_ref_command.ab index 5cbc308b..6891d6ec 100644 --- a/src/tests/validity/variable_ref_command.ab +++ b/src/tests/validity/variable_ref_command.ab @@ -3,5 +3,5 @@ fun foo(ref a) { } let a = "" -unsafe foo(a) +trust foo(a) echo a diff --git a/src/tests/validity/variable_ref_function_invocation.ab b/src/tests/validity/variable_ref_function_invocation.ab index 8ae39b30..597cda86 100644 --- a/src/tests/validity/variable_ref_function_invocation.ab +++ b/src/tests/validity/variable_ref_function_invocation.ab @@ -2,7 +2,7 @@ // "sram" fun reverse(input: Text): Text { - return unsafe $echo {input} | rev$ + return trust $echo {input} | rev$ } fun foo(ref a) { @@ -10,5 +10,5 @@ fun foo(ref a) { } let a = "" -unsafe foo(a) +trust foo(a) echo a diff --git a/src/utils/context.rs b/src/utils/context.rs index 975b08b2..d08e1ec7 100644 --- a/src/utils/context.rs +++ b/src/utils/context.rs @@ -112,8 +112,8 @@ pub struct Context { pub is_loop_ctx: bool, /// Determines if the context is in the main block pub is_main_ctx: bool, - /// Determines if the context is in an unsafe block - pub is_unsafe_ctx: bool, + /// Determines if the context is in a trust block + pub is_trust_ctx: bool, /// This is a list of ids of all the public functions in the file pub pub_funs: Vec, /// The return type of the currently parsed function @@ -134,7 +134,7 @@ impl Context { is_fun_ctx: false, is_loop_ctx: false, is_main_ctx: false, - is_unsafe_ctx: false, + is_trust_ctx: false, pub_funs: vec![], fun_ret_type: None, cc_flags: HashSet::new(), diff --git a/test_files/str/trim.ab b/test_files/str/trim.ab index 256efe64..c3a527da 100644 --- a/test_files/str/trim.ab +++ b/test_files/str/trim.ab @@ -1,5 +1,5 @@ pub fun trim(text) { - return unsafe $echo "{text}" | xargs$ + return trust $echo "{text}" | xargs$ } main {