Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rishav-karanjit committed Feb 4, 2025
1 parent 0c76cda commit f7af900
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ public String mapShape(final MapShape shape) {
someWrapIfRequired = "Wrappers.Companion_Option_.Create_Some_(%s)";
returnType = "Wrappers.Option";
}
var nilCheck =
"if %s == nil {return %s}".formatted(dataSource, nilWrapIfRequired);
var nilCheck = "";
if (isPointerType) {
nilCheck =
"if %s == nil {return %s}".formatted(dataSource, nilWrapIfRequired);
}
typeConversionMethodBuilder.append(
"""
func () %s {
Expand Down Expand Up @@ -371,24 +374,29 @@ public String stringShape(final StringShape shape) {
shape,
context.symbolProvider().toSymbol(shape)
);

var noEnumMatchedCheck = "";
if (this.isOptional) {
someWrapIfRequired = "Wrappers.Companion_Option_.Create_Some_(%s)";
returnType = "Wrappers.Option";
// In AWS SDK, some shapes don't have required trait and also don't have pointers in it.
// This will result the default value of the string be "" if not provided.
noEnumMatchedCheck =
"""
if index == len(%s.Values()) {
return Wrappers.Companion_Option_.Create_None_()
}
""".formatted(dataSource);
}

return """
func () %s {
var index int
numOfValues := len(%s.Values())
for _, enumVal := range %s.Values() {
index++
if enumVal == %s{
break;
}
if index == numOfValues {
return Wrappers.Companion_Option_.Create_None_()
}
%s
}
var enum interface{}
for allEnums, i := dafny.Iterate(%s{}.AllSingletonConstructors()), 0; i < index; i++ {
Expand All @@ -403,7 +411,7 @@ var enum interface{}
returnType,
dataSource,
dataSource,
dataSource,
noEnumMatchedCheck,
DafnyNameResolver.getDafnyCompanionStructType(
shape,
context.symbolProvider().toSymbol(shape)
Expand Down

0 comments on commit f7af900

Please sign in to comment.