From e6fad82b877431c26e548bc5df08633dd295914c Mon Sep 17 00:00:00 2001 From: StunxFS <56417208+StunxFS@users.noreply.github.com> Date: Thu, 27 Oct 2022 03:38:57 -0400 Subject: [PATCH] v.eval: support `unsafe` expr (#16224) --- vlib/v/eval/expr.v | 5 ++++- vlib/v/eval/testdata/unsafe_expr.out | 1 + vlib/v/eval/testdata/unsafe_expr.vv | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 vlib/v/eval/testdata/unsafe_expr.out create mode 100644 vlib/v/eval/testdata/unsafe_expr.vv diff --git a/vlib/v/eval/expr.v b/vlib/v/eval/expr.v index 73ae3b05d4..9d49629f39 100644 --- a/vlib/v/eval/expr.v +++ b/vlib/v/eval/expr.v @@ -526,12 +526,15 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object { return res } + ast.UnsafeExpr { + return e.expr(expr.expr, expecting) + } ast.AnonFn, ast.ArrayDecompose, ast.AsCast, ast.Assoc, ast.AtExpr, ast.CTempVar, ast.ChanInit, ast.Comment, ast.ComptimeCall, ast.ComptimeSelector, ast.ComptimeType, ast.ConcatExpr, ast.DumpExpr, ast.EmptyExpr, ast.EnumVal, ast.GoExpr, ast.IfGuardExpr, ast.IndexExpr, ast.IsRefType, ast.Likely, ast.LockExpr, ast.MapInit, ast.MatchExpr, ast.Nil, ast.NodeError, ast.None, ast.OffsetOf, ast.OrExpr, ast.RangeExpr, ast.SelectExpr, - ast.SqlExpr, ast.TypeNode, ast.TypeOf, ast.UnsafeExpr { + ast.SqlExpr, ast.TypeNode, ast.TypeOf { e.error('unhandled expression ${typeof(expr).name}') } } diff --git a/vlib/v/eval/testdata/unsafe_expr.out b/vlib/v/eval/testdata/unsafe_expr.out new file mode 100644 index 0000000000..27ba77ddaf --- /dev/null +++ b/vlib/v/eval/testdata/unsafe_expr.out @@ -0,0 +1 @@ +true diff --git a/vlib/v/eval/testdata/unsafe_expr.vv b/vlib/v/eval/testdata/unsafe_expr.vv new file mode 100644 index 0000000000..925b1060c2 --- /dev/null +++ b/vlib/v/eval/testdata/unsafe_expr.vv @@ -0,0 +1,3 @@ +unsafe { + println(true) +}