-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cgen: fix if guard stmts return generated code + fix auto generated o…
…ption map comparison code (#20169)
- Loading branch information
Showing
3 changed files
with
98 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import maps | ||
import x.json2 | ||
|
||
pub type Locale = string | ||
|
||
pub struct ApplicationCommandOptionChoice { | ||
pub: | ||
name string | ||
name_localizations ?map[Locale]string | ||
} | ||
|
||
pub fn ApplicationCommandOptionChoice.parse(j json2.Any) !ApplicationCommandOptionChoice { | ||
match j { | ||
map[string]json2.Any { | ||
return ApplicationCommandOptionChoice{ | ||
name: j['name']! as string | ||
name_localizations: if m := j['name_localizations'] { | ||
maps.to_map[string, json2.Any, Locale, string](m as map[string]json2.Any, | ||
fn (k string, v json2.Any) (Locale, string) { | ||
return k, v as string | ||
}) | ||
} else { | ||
none | ||
} | ||
} | ||
} | ||
else { | ||
return error('expected application command option choice to be object, got ${j.type_name()}') | ||
} | ||
} | ||
} | ||
|
||
fn test_main() { | ||
var := ApplicationCommandOptionChoice.parse({ | ||
'name': json2.Any('foo') | ||
'name_localizations': { | ||
'name': json2.Any('foo') | ||
} | ||
})! | ||
assert dump(var) == var | ||
} |