Skip to content

Commit 578ca33

Browse files
committed
- fixes a bug where type specific indexers would fail to build in Go
Signed-off-by: Vincent Biret <[email protected]>
1 parent a98650f commit 578ca33

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
- Renamed the Shell language to CLI. [#3023](https://github.com/microsoft/kiota/issues/3023)
1818
- Fixed a bug where and extraneous indexer would be generated for CLI. [#3088](https://github.com/microsoft/kiota/issues/3088)
19+
- Fixed a bug where type specific indexers would fail to build in Go. [#3090](https://github.com/microsoft/kiota/issues/3090)
1920

2021
## [1.5.0] - 2023-08-04
2122

src/Kiota.Builder/Refiners/GoRefiner.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ private static void AddErrorImportForEnums(CodeElement currentElement)
515515
method.Parameters.Any(x => x.IsOfKind(CodeParameterKind.Path) &&
516516
!typeToSkipStrConv.Contains(x.Type.Name)),
517517
"strconv", "FormatBool"),
518+
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.IndexerBackwardCompatibility) &&
519+
method.OriginalIndexer is CodeIndexer indexer && !indexer.IndexParameter.Type.Name.Equals("string", StringComparison.OrdinalIgnoreCase),
520+
"strconv", "FormatInt"),
518521
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.Serializer),
519522
"github.com/microsoft/kiota-abstractions-go/serialization", "SerializationWriter"),
520523
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.Deserializer, CodeMethodKind.Factory),

src/Kiota.Builder/Writers/Go/GoConventionService.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,21 @@ internal void AddParametersAssignment(LanguageWriter writer, CodeTypeBase? pathP
211211
foreach (var p in parameters)
212212
{
213213
var isStringStruct = !p.Item1.IsNullable && p.Item1.Name.Equals("string", StringComparison.OrdinalIgnoreCase);
214-
var defaultValue = isStringStruct ? "\"\"" : "nil";
215-
var pointerDereference = isStringStruct ? string.Empty : "*";
216-
writer.StartBlock($"if {p.Item3} != {defaultValue} {{");
214+
var (defaultValue, pointerDereference, shouldCheckNullability) = (isStringStruct, p.Item1.IsNullable) switch
215+
{
216+
(true, _) => ("\"\"", string.Empty, true),
217+
(_, true) => ("nil", "*", true),
218+
(_, false) => (string.Empty, string.Empty, false),
219+
};
220+
if (shouldCheckNullability)
221+
writer.StartBlock($"if {p.Item3} != {defaultValue} {{");
217222
writer.WriteLine($"{pathParametersTarget}[\"{p.Item2}\"] = {GetValueStringConversion(p.Item1.Name, pointerDereference + p.Item3)}");
218-
writer.CloseBlock();
223+
if (shouldCheckNullability)
224+
writer.CloseBlock();
219225
}
220226
}
221227
#pragma warning restore CA1822 // Method should be static
222-
private const string StrConvHash = "i53ac87e8cb3cc9276228f74d38694a208cacb99bb8ceb705eeae99fb88d4d274";
228+
internal const string StrConvHash = "i53ac87e8cb3cc9276228f74d38694a208cacb99bb8ceb705eeae99fb88d4d274";
223229
private const string TimeFormatHash = "i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e";
224230
private static string GetValueStringConversion(string typeName, string reference)
225231
{

0 commit comments

Comments
 (0)