File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -104,6 +104,10 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
104104 if c.comptime.inside_comptime_for && node.cond.field_name in ['name' , 'typ' ] {
105105 // hack: `typ` is just for bypass the error test, because we don't know it is a type match or a value match righ now
106106 comptime_match_cond_value = c.comptime.comptime_for_field_value.name
107+ } else if mut node.cond.expr is ast.Ident
108+ && node.cond.gkind_field in [.typ, .unaliased_typ] {
109+ left_type := c.get_expr_type (node.cond.expr)
110+ comptime_match_cond_value = c.table.type_to_str (left_type)
107111 } else {
108112 c.error ('`${node .cond }` is not `\$ for` field.name.' , node.cond.pos)
109113 return ast.void_type
Original file line number Diff line number Diff line change 1+ fn check_unaliased [T](t T) bool {
2+ $match T.unaliased_typ {
3+ int {
4+ return true
5+ }
6+ $else {
7+ return false
8+ }
9+ }
10+ }
11+
12+ fn check_typ [T](t T) bool {
13+ $match T.typ {
14+ int {
15+ return true
16+ }
17+ $else {
18+ return false
19+ }
20+ }
21+ }
22+
23+ type FooInt = int
24+
25+ fn test_main () {
26+ assert check_unaliased (1 )
27+ assert ! check_unaliased ('' )
28+ assert ! check_unaliased (1.2 )
29+ assert check_unaliased (FooInt (0 ))
30+
31+ assert check_typ (1 )
32+ assert ! check_typ ('' )
33+ assert ! check_typ (1.2 )
34+ assert ! check_typ (FooInt (0 ))
35+ }
You can’t perform that action at this time.
0 commit comments