File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1648,6 +1648,13 @@ fn (mut c Checker) const_decl(mut node ast.ConstDecl) {
16481648 field.expr.is_expr = true
16491649 field.expr.typ = (branch.stmts.last () as ast.ExprStmt ).typ
16501650 field.typ = field.expr.typ
1651+ // update ConstField object's type in table
1652+ if mut obj := c.file.global_scope.find (field.name) {
1653+ if mut obj is ast.ConstField {
1654+ obj.typ = field.typ
1655+ }
1656+ }
1657+ break
16511658 }
16521659 }
16531660 }
Original file line number Diff line number Diff line change 1+ import term
2+
3+ const (
4+ color = $if windows {
5+ term.bright_cyan ('WINDOWS' )
6+ } $else {
7+ term.bright_green ('UNIX' )
8+ }
9+ )
10+
11+ fn test_const_from_comptime_if_expr () {
12+ salutation := 'hello'
13+ val := match salutation {
14+ 'hello' { color + ' some text' }
15+ 'goodbyte' { color + ' some other text' }
16+ else { 'invalid' }
17+ }
18+ println (val)
19+ assert true
20+ }
You can’t perform that action at this time.
0 commit comments