diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index efabaef41b..c7c5a90a4d 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -112,8 +112,9 @@ pub type Node = CallArg pub struct TypeNode { pub: - typ Type pos token.Pos +pub mut: + typ Type } pub enum ComptimeTypeKind { diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index ad58cd19bd..5fd29abbf5 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -607,6 +607,10 @@ fn (mut p Parser) prefix_expr() ast.Expr { right = right.expr } } + if mut right is ast.TypeNode { + right.typ = right.typ.ref() + return right + } } mut or_stmts := []ast.Stmt{} mut or_kind := ast.OrKind.absent diff --git a/vlib/v/tests/inout/printing_comptime_if.out b/vlib/v/tests/inout/printing_comptime_if.out new file mode 100644 index 0000000000..bb2a3b2c06 --- /dev/null +++ b/vlib/v/tests/inout/printing_comptime_if.out @@ -0,0 +1 @@ +T is &u8 diff --git a/vlib/v/tests/inout/printing_comptime_if.vv b/vlib/v/tests/inout/printing_comptime_if.vv new file mode 100644 index 0000000000..6cdeb1841a --- /dev/null +++ b/vlib/v/tests/inout/printing_comptime_if.vv @@ -0,0 +1,10 @@ +fn main() { + c := c'cstr' + proc(c) +} + +fn proc(input T) { + $if T is &u8 { + println('T is $T.name') + } +}