Skip to content

Commit

Permalink
parser: allow type as field type on params struct construction (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Dec 8, 2024
1 parent 6df25af commit cebd999
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/parser/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn (mut p Parser) call_args() []ast.CallArg {
array_decompose = true
}
mut expr := ast.empty_expr
if p.tok.kind == .name && p.peek_tok.kind == .colon {
if p.tok.kind in [.name, .key_type] && p.peek_tok.kind == .colon {
// `foo(key:val, key2:val2)`
expr = p.struct_init('void_type', .short_syntax, false)
} else {
Expand Down
24 changes: 24 additions & 0 deletions vlib/v/tests/keyword_as_params_field_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@[params]
struct FooParams {
type FooType = .first
}

enum FooType {
first
second
}

fn foo(params FooParams) string {
match params.type {
.first {
return 'First'
}
.second {
return 'Second'
}
}
}

fn test_main() {
assert foo(type: .second) == 'Second'
}

0 comments on commit cebd999

Please sign in to comment.