Skip to content

Commit 5fb8654

Browse files
feat(go): handle unhandled orphanShapes (#761)
* Enable orphan shape test model for Go * Support map, list, boolean and blob orphan shapes * Generate shape conversion for orphan shapes if needed
1 parent 8e428ca commit 5fb8654

File tree

7 files changed

+314
-31
lines changed

7 files changed

+314
-31
lines changed

TestModels/OrphanedShapes/runtimes/go/ImplementationFromDafny-go/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/smithy-lang/smithy-dafny/TestModels/OrphanedShapes
33
go 1.23.0
44

55
require (
6-
github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.1
7-
github.com/dafny-lang/DafnyStandardLibGo v0.0.0
6+
github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.2
7+
github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library v0.0.0
88
)
99

10-
replace github.com/dafny-lang/DafnyStandardLibGo => ../../../../dafny-dependencies/StandardLibrary/runtimes/go/ImplementationFromDafny-go/
10+
replace github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library => ../../../../dafny-dependencies/StandardLibrary/runtimes/go/ImplementationFromDafny-go/

TestModels/OrphanedShapes/runtimes/go/TestsFromDafny-go/ExternDefinitions/extern.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package ExternDefinitions
22

33
import (
4-
"fmt"
5-
6-
Wrappers "github.com/dafny-lang/DafnyStandardLibGo/Wrappers"
4+
Wrappers "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Wrappers"
75
OrphanedResource "github.com/smithy-lang/smithy-dafny/TestModels/OrphanedShapes/OrphanedResource"
86
SimpleOrphanedTypes "github.com/smithy-lang/smithy-dafny/TestModels/OrphanedShapes/SimpleOrphanedTypes"
97
simpleorphanedsmithygenerated "github.com/smithy-lang/smithy-dafny/TestModels/OrphanedShapes/simpleorphanedsmithygenerated"
@@ -12,12 +10,16 @@ import (
1210

1311
var _ Wrappers.Dummy__
1412

15-
// TODO: Finish implementation.
16-
// This is missing structure converter.
13+
// TODO: Remove this once Dafny bug is fixed.
14+
// Dafny bug: https://t.corp.amazon.com/9a9028fd-2711-4843-b8f0-09965f7e61a7/communication#f03694be-7410-47f9-866d-e43093b018f9
15+
var m_ExternDefinitions = CompanionStruct_Default___{}
1716

1817
func (CompanionStruct_Default___) InitializeOrphanedStructure(input SimpleOrphanedTypes.OrphanedStructure) SimpleOrphanedTypes.OrphanedStructure {
19-
// Missing Structure converter
20-
return input
18+
nativeInput := simpleorphanedsmithygenerated.OrphanedStructure_FromDafny(input)
19+
stringToReplace := "the extern MUST use Smithy-generated conversions to set this value in the native structure"
20+
nativeInput.StringValue = &stringToReplace
21+
dafnyInitializedStructure := simpleorphanedsmithygenerated.OrphanedStructure_ToDafny(nativeInput)
22+
return dafnyInitializedStructure
2123
}
2224

2325
func (CompanionStruct_Default___) CallNativeOrphanedResource(input *OrphanedResource.OrphanedResource) Wrappers.Result {
@@ -32,7 +34,7 @@ func (CompanionStruct_Default___) CallNativeOrphanedResource(input *OrphanedReso
3234
}
3335

3436
func (CompanionStruct_Default___) CallNativeOrphanedError(input SimpleOrphanedTypes.Error) SimpleOrphanedTypes.Error {
35-
native_error := simpleorphanedsmithygenerated.Error_FromDafny(input)
37+
native_error := simpleorphanedsmithygenerated.Error_FromDafny(input).(simpleorphanedsmithygeneratedtypes.OrphanedError)
3638
native_error.Message = "the extern MUST set this string using the catch-all error converter, NOT the orphaned error-specific converter"
3739
dafny_error_again := simpleorphanedsmithygenerated.Error_ToDafny(native_error)
3840
return dafny_error_again

TestModels/OrphanedShapes/runtimes/go/TestsFromDafny-go/go.mod

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ module github.com/smithy-lang/smithy-dafny/TestModels/OrphanedShapes/test
22

33
go 1.23.0
44

5-
require github.com/dafny-lang/DafnyStandardLibGo v0.0.0
6-
75
require (
8-
github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.1
6+
github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library v0.0.0
7+
github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.2
98
github.com/smithy-lang/smithy-dafny/TestModels/OrphanedShapes v0.0.0
109
)
1110

1211
replace github.com/smithy-lang/smithy-dafny/TestModels/OrphanedShapes v0.0.0 => ../ImplementationFromDafny-go
1312

14-
replace github.com/dafny-lang/DafnyStandardLibGo => ../../../../dafny-dependencies/StandardLibrary/runtimes/go/ImplementationFromDafny-go/
13+
replace github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library => ../../../../dafny-dependencies/StandardLibrary/runtimes/go/ImplementationFromDafny-go/

codegen/smithy-dafny-codegen-test/src/test/java/software/amazon/polymorph/smithygo/GoTestModels.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class GoTestModels extends TestModelTest {
2121
DISABLED_TESTS.add("AggregateReferences");
2222
DISABLED_TESTS.add("Documentation");
2323
DISABLED_TESTS.add("LanguageSpecificLogic");
24-
// Needs work to generate some missing orphaned shape conversion methods
25-
DISABLED_TESTS.add("OrphanedShapes");
2624
DISABLED_TESTS.add("SimpleTypes/BigDecimal");
2725
DISABLED_TESTS.add("SimpleTypes/BigInteger");
2826
DISABLED_TESTS.add("SimpleTypes/SimpleByte");

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithygo/localservice/DafnyLocalServiceDirectedCodegen.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ protected void generateOrphanedShapesForService(
213213
ShapeType.INTEGER,
214214
ShapeType.UNION,
215215
ShapeType.STRING,
216-
ShapeType.LONG
216+
ShapeType.LONG,
217+
ShapeType.MAP,
218+
ShapeType.LIST,
219+
ShapeType.BOOLEAN,
220+
ShapeType.BLOB
217221
);
218222

219223
for (final var shapeToGenerate : orderedShapes) {

0 commit comments

Comments
 (0)