parser: short struct syntax for all structs
parent
67756c53dc
commit
4de8d3ae8c
|
@ -925,9 +925,6 @@ fn (p mut Parser) factor() string {
|
||||||
}
|
}
|
||||||
peek2 := p.tokens[p.token_idx + 1]
|
peek2 := p.tokens[p.token_idx + 1]
|
||||||
if p.peek() == .rcbr || (p.peek() == .name && peek2.tok == .colon) {
|
if p.peek() == .rcbr || (p.peek() == .name && peek2.tok == .colon) {
|
||||||
if !p.expected_type.ends_with('Config') {
|
|
||||||
p.error('short struct initialization syntax only works with structs that end with `Config`')
|
|
||||||
}
|
|
||||||
return p.struct_init(p.expected_type)
|
return p.struct_init(p.expected_type)
|
||||||
}
|
}
|
||||||
// { user | name :'new name' }
|
// { user | name :'new name' }
|
||||||
|
|
|
@ -203,9 +203,14 @@ struct Config {
|
||||||
fn foo_config(c Config) {
|
fn foo_config(c Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn foo2(u User) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fn test_config() {
|
fn test_config() {
|
||||||
foo_config({n: 10, def: 20})
|
foo_config({n: 10, def: 20})
|
||||||
foo_config({})
|
foo_config({})
|
||||||
|
foo2({name:'Peter'})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue