Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a codegen bug in positional? #683

Draft
wants to merge 1 commit into
base: main-1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion TestModels/Positional/Model/positional.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use aws.polymorph#reference
service SimplePositional {
version: "2021-11-01",
resources: [],
operations: [ GetResource, GetResourcePositional ],
operations: [ GetResource, GetResourcePositional, GetIntegerInputPosition, GetIntegerOutputPosition ],
errors: [ SimplePositionalException ],
}

Expand Down Expand Up @@ -73,3 +73,33 @@ structure GetResourcePositionalOutput {
@required
output: SimpleResourceReference
}

operation GetIntegerInputPosition {
input: GetIntegerInputPositionInput
output: GetIntegerInputPositionOutput,
}

@positional
structure GetIntegerInputPositionInput {
@required
value: Integer
}

structure GetIntegerInputPositionOutput {
value: Integer
}

operation GetIntegerOutputPosition {
input: GetIntegerOutputPositionInput
output: GetIntegerOutputPositionOutput,
}

structure GetIntegerOutputPositionInput {
value: Integer
}

@positional
structure GetIntegerOutputPositionOutput {
@required
value: Integer
}
30 changes: 22 additions & 8 deletions TestModels/Positional/src/SimplePositionalImpl.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ module SimplePositionalImpl refines AbstractSimplePositionalOperations {
{true}
function ModifiesInternalConfig(config: InternalConfig): set<object>
{{}}

predicate GetResourceEnsuresPublicly(input: GetResourceInput , output: Result<GetResourceOutput, Error>)
{true}



method GetResource ( config: InternalConfig , input: GetResourceInput )
returns (output: Result<GetResourceOutput, Error>)

{
var resource := new SimpleResource.SimpleResource(
input.name
Expand All @@ -31,20 +29,36 @@ module SimplePositionalImpl refines AbstractSimplePositionalOperations {
return Success(result);
}


predicate GetResourcePositionalEnsuresPublicly(input: string , output: Result<ISimpleResource, Error>)
{true}



// @positional allows use to accept the input parameters directly without the input structure
method GetResourcePositional ( config: InternalConfig , input: string )
returns (output: Result<ISimpleResource, Error>)

{
var resource := new SimpleResource.SimpleResource(input);

// @positional allows use to return the result without the output structure
return Success(resource);
}
}

predicate GetIntegerInputPositionEnsuresPublicly(input: int32 , output: Result<GetIntegerInputPositionOutput, Error>)
{true}

method GetIntegerInputPosition ( config: InternalConfig , input: int32 )
returns (output: Result<GetIntegerInputPositionOutput, Error>)
{
var res := GetIntegerInputPositionOutput(value := Some(input));
return Success(res);
}

predicate GetIntegerOutputPositionEnsuresPublicly(input: GetIntegerOutputPositionInput , output: Result<int32, Error>)
{true}

method GetIntegerOutputPosition ( config: InternalConfig , input: GetIntegerOutputPositionInput )
returns (output: Result<int32, Error>)
{
expect input.value.Some?;
return Success(input.value.UnwrapOr(-1));
}
}
24 changes: 24 additions & 0 deletions TestModels/Positional/test/SimplePositionalImplTest.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module {:options "--function-syntax:4"} SimplePositionalImplTest {
{
TestGetResource(client);
TestGetResourcePositional(client);
GetIntegerInputPosition(client);
GetIntegerOutputPosition(client);
}

method TestGetResource(client: Types.ISimplePositionalClient)
Expand Down Expand Up @@ -41,6 +43,28 @@ module {:options "--function-syntax:4"} SimplePositionalImplTest {
expect getNameOutput.name == "TestPositional";
}

method GetIntegerInputPosition(client: Types.ISimplePositionalClient)
requires client.ValidState()
modifies client.Modifies
ensures client.ValidState()
{
var input := 5;
var ret :- expect client.GetIntegerInputPosition(input);
expect ret.value.UnwrapOr(0) == input;
}

method GetIntegerOutputPosition(client: Types.ISimplePositionalClient)
requires client.ValidState()
modifies client.Modifies
ensures client.ValidState()
{
var inputInteger:= 5;
var input := Types.GetIntegerOutputPositionInput(value:= Some(inputInteger));
var ret :- expect client.GetIntegerOutputPosition(input);
expect ret == inputInteger;
}


method {:test} TestDefaultConfig() {
var client :- expect SimplePositional.SimplePositional();
TestClient(client);
Expand Down
Loading