Skip to content

Commit 980d8d9

Browse files
authored
Merge pull request 1Password#189 from hculea/hculea/format-variant-type-explicitly
Explicitly format variant types in Go
2 parents 4a73bd4 + 0870aae commit 980d8d9

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

core/src/language/go.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ impl Go {
278278
));
279279

280280
if let Some(variant_type) = variant_type {
281-
let variant_type = self.acronyms_to_uppercase(&variant_type);
282281
let (variant_pointer, variant_deref, variant_ref) =
283282
match (v, custom_structs.contains(&variant_type.as_str())) {
284283
(RustEnumVariant::AnonymousStruct { .. }, ..) | (.., true) => {
@@ -287,17 +286,19 @@ impl Go {
287286
_ => ("", "*", "&"),
288287
};
289288

289+
let formatted_variant_type = self.acronyms_to_uppercase(&variant_type);
290+
290291
decoding_cases.push(format!(
291-
"\t\tvar res {variant_type}
292+
"\t\tvar res {formatted_variant_type}
292293
\t\t{short_name}.{content_field} = &res
293294
",
294-
variant_type = variant_type,
295+
formatted_variant_type = formatted_variant_type,
295296
short_name = struct_short_name,
296297
content_field = content_field,
297298
));
298299
variant_accessors.push(format!(
299-
r#"func ({short_name} {full_name}) {variant_name}() {variant_pointer}{variant_type} {{
300-
res, _ := {short_name}.{content_field}.(*{variant_type})
300+
r#"func ({short_name} {full_name}) {variant_name}() {variant_pointer}{formatted_variant_type} {{
301+
res, _ := {short_name}.{content_field}.(*{formatted_variant_type})
301302
return {variant_deref}res
302303
}}
303304
"#,
@@ -306,11 +307,11 @@ impl Go {
306307
variant_name = variant_name,
307308
variant_pointer = variant_pointer,
308309
variant_deref = variant_deref,
309-
variant_type = variant_type,
310+
formatted_variant_type = formatted_variant_type,
310311
content_field = content_field,
311312
));
312313
variant_constructors.push(format!(
313-
r#"func New{variant_type_const}(content {variant_pointer}{variant_type}) {struct_name} {{
314+
r#"func New{variant_type_const}(content {variant_pointer}{formatted_variant_type}) {struct_name} {{
314315
return {struct_name}{{
315316
{tag_field}: {variant_type_const},
316317
{content_field}: {variant_ref}content,
@@ -321,7 +322,7 @@ impl Go {
321322
tag_field = tag_field,
322323
variant_type_const = variant_type_const,
323324
variant_pointer = variant_pointer,
324-
variant_type = variant_type,
325+
formatted_variant_type = formatted_variant_type,
325326
variant_ref = variant_ref,
326327
content_field = content_field,
327328
));

core/src/rust_types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ pub enum RustType {
156156
/// - `SomeStruct<String>`
157157
/// - `SomeEnum<u32>`
158158
/// - `SomeTypeAlias<(), &str>`
159+
///
159160
/// However, there are some generic types that are considered to be _special_. These
160161
/// include `Vec<T>` `HashMap<K, V>`, and `Option<T>`, which are part of `SpecialRustType` instead
161162
/// of `RustType::Generic`.

0 commit comments

Comments
 (0)